This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_and_belongs_to_many :associates, | |
:class_name => "User", | |
:join_table => "connections", | |
:association_foreign_key => "connection_user_id" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyApp::Application.routes.draw do | |
resources :users | |
resources :associates | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ability | |
include CanCan::Ability | |
def initialize(user) | |
user ||= User.new | |
resourceful_actions = [ | |
:index, | |
:show, | |
:new, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ability | |
include CanCan::Ability | |
def initialize(user) | |
user ||= User.new | |
resourceful_actions = [ | |
:index, | |
:show, | |
:new, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module JsonHashifier | |
# Converts an ActiveRecord model object to a JSON appropriate Hash. | |
# @param [Hash] options | |
# @option options [String] :timezone The timezone to apply to the created_at & updated_at columns | |
# @option options [Integer] :timezone_offset The timezone offset that should be used to determine the timezone | |
# @option options [String] :date_format The strftime format to apply to the created_at & updated_at columns | |
# @option options [Boolean] :indifferent_access Indicates whether or not to return a HashWithIndifferentAccess | |
# @options options [Array<String,Symbol>] :whitelist A white list of attributes to keep in the Hash. Defaults to all attributes. | |
# @options options [Array<String,Symbol>] :methods A list of methods to invoke for inclusion in the Hash. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# search all installed gems | |
$ rvm gemdir | xargs ack "def fail" {} | |
# search within a specific gem | |
$ bundle show cancan | xargs ack "def can?" {} | |
# open a gem in Sublime | |
$ bundle show warden | xargs subl {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def current_method_name | |
caller[0][/`([^']*)'/, 1].to_sym | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# checkout the readme from the master branch | |
`git checkout gh-pages; git checkout master README.md` | |
path = `pwd`.gsub(/\n/, "") | |
readme_path = File.join(path, "README.md") | |
index_path = File.join(path, "index.md") | |
# write the index readme file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
# Divides the Array into equally sized chunks. | |
# | |
# @example | |
# list = ["a", "b", "c", "d", "e", "f"] | |
# list.divide(3) # => [["a", "b"], ["c", "d"], ["e", "f"]] | |
# | |
# @param [Integer] count A recommended number of chunks (sub lists) to create. | |
# The calculated chunk size is rounded up, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An RSpec shim that provides old school assert methods. | |
# My contention is that its better to write tests in the same fashion that you write the app. | |
# This approach is faster since it does away with the context switching between typical everyday logic and a wonky DSL. | |
# The barrier to entry is also lower for the unitiated RSpec user. | |
# | |
# Consider the following example from the RSpec docs. | |
# expect(order.total).to eq(Money.new(5.55, :USD)) | |
# | |
# Rewritten with GrumpyOldMan. | |
# assert_equal order.total, Money.new(5.55, :USD) |