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 has_role?(role) | |
# if list isn't already assigned to something, create an array of the names of my roles | |
list ||= self.roles.map(&:name) | |
# if list includes the string representation of the passed-in role [assumed to be the name] or if the list includes the string 'admin' [assumed to be the administrative role] return true | |
list.include?(role.to_s) || list.include?('admin') | |
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
# from: http://pivotallabs.com/users/alex/blog/articles/865-monkey-patch-du-jour | |
module ActiveRecord | |
module ConnectionAdapters | |
class AbstractAdapter | |
def log_info(sql, name, ms) | |
if @logger && @logger.debug? | |
@logger.debug("#{sql}, #{name}, #{ms}") | |
c = caller.detect{|line| line !~ /(activerecord|active_support|__DELEGATION__|\/lib\/|\/vendor\/plugins|\/vendor\/gems)/i} | |
c.gsub!("#{File.expand_path(File.dirname(RAILS_ROOT))}/", '') if defined?(RAILS_ROOT) | |
name = '%s (%.1fms) %s' % [name || 'SQL', ms, c] |
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 self.included(receiver) | |
receiver.class_eval <<-RUBY | |
named_scope :latest_before, lambda {|time| {:conditions => ['created_at < ?', time]}} | |
RUBY | |
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
def assert_close_enough(target, actual, message = nil) | |
lower = (0.9 * target.to_f).floor | |
upper = (1.1 * target.to_f).ceil | |
full_message = build_message(message, | |
"<?-?> expected but was\n<?>.\n", lower, upper, actual) | |
assert_block(full_message) { actual >= lower and actual <= upper } | |
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
sudo gem install ZenTest actionmailer actionpack activerecord activeresource activesupport autotest-fsevent autotest-rails beanstalk-client capistrano capistrano-ext columnize ctran-annotate curb engineyard-eycap fastercsv fastthread highline hoe httpclient libxml-ruby linecache mysql net-scp net-sftp net-ssh net-ssh-gateway nokogiri passenger plist rack rails rake redgreen rspec rspec-rails ruby-debug ruby-debug-base rubyforge rubyist-aasm sevenwire-forgery soap4r sys-uname taf2-curb taf2-rmem thoughtbot-factory_girl |
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
lrwxr-xr-x 1 root wheel 76 May 21 05:31 /usr/bin/ruby -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby |
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
ted@ceylon /usr/bin »ls -al | grep -i ruby | |
lrwxr-xr-x 1 root wheel 75 May 21 05:31 erb -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/erb | |
lrwxr-xr-x 1 root wheel 71 May 21 05:31 gem -> ../../System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/gem | |
lrwxr-xr-x 1 root wheel 75 May 21 05:31 irb -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/irb | |
-rwxr-xr-x 1 root wheel 435 Jul 4 08:14 multiruby | |
-rwxr-xr-x 1 root wheel 441 Jul 4 08:14 multiruby_setup | |
lrwxr-xr-x 1 root wheel 76 May 21 05:31 rdoc -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/rdoc | |
lrwxr-xr-x 1 root wheel 74 May 21 05:31 ri -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ri | |
lrwxr-xr-x 1 root wheel 71 Jul 8 22:13 ruby -> /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby | |
-rwxr-xr-x 1 root w |
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
*** LOCAL GEMS *** | |
actionmailer (2.3.2, 1.3.6) | |
actionpack (2.3.2, 1.13.6) | |
actionwebservice (1.2.6) | |
activerecord (2.3.2, 1.15.6) | |
activeresource (2.3.2) | |
activesupport (2.3.2, 1.4.4) | |
acts_as_ferret (0.4.4, 0.4.1) | |
autotest-fsevent (0.1.1) |
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
# threads = Array(servers).map { |server| establish_connection_to(server, failed_servers) } | |
# threads.each { |t| t.join } | |
Array(servers).each { |server| safely_establish_connection_to(server, Thread.current, failed_servers) } |
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 Time | |
def no_minutes | |
return self - self.min.minutes - self.sec.seconds | |
end | |
end |