Sha256: 7969ae4e6aaaefdd248e1df9cec8f361c28c8d6f357c7244814233c763346c31

Contents?: true

Size: 737 Bytes

Versions: 20

Compression:

Stored size: 737 Bytes

Contents

# http://www.clarkware.com/cgi/blosxom/2007/09/03#ConsoleFindShortcut
# Mike Clark's find() shortcut for Rails console

# Creates shortcut methods for finding models.
UTILITY_BELT_IRB_STARTUP_PROCS[:define_model_find_shortcuts] = lambda do
  if defined? ActiveRecord::Base || defined? ActiveResource::Base
    model_files = Dir.glob("app/models/**/*.rb")
    table_names = model_files.map { |f| File.basename(f).split('.')[0..-2].join }
    table_names.each do |table_name|
      Object.instance_eval do
        define_method(table_name) do |*args|
          table_name.camelize.constantize.send(:find, *args)
        end
      end
    end
  end
end
# note: Mike wrote this for ARec, but it works on ARes too since it doesn't hit the DB

Version data entries

20 entries across 20 versions & 6 rubygems

Version Path
FreedomCoder-utility_belt-1.1.1.2 lib/utility_belt/rails_finder_shortcut.rb
FreedomCoder-utility_belt-1.1.1 lib/utility_belt/rails_finder_shortcut.rb
akitaonrails-utility_belt-1.0.10 lib/utility_belt/rails_finder_shortcut.rb
akitaonrails-utility_belt-1.0.11 lib/utility_belt/rails_finder_shortcut.rb
akitaonrails-utility_belt-1.0.12 lib/utility_belt/rails_finder_shortcut.rb
mguterl-utility_belt-1.0.7 lib/utility_belt/rails_finder_shortcut.rb
rwilcox-utility_belt-1.0.7 lib/utility_belt/rails_finder_shortcut.rb
rwilcox-utility_belt-1.0.9 lib/utility_belt/rails_finder_shortcut.rb
timocratic-utility_belt-1.0.7.1 lib/utility_belt/rails_finder_shortcut.rb
timocratic-utility_belt-1.0.7.2 lib/utility_belt/rails_finder_shortcut.rb
timocratic-utility_belt-1.0.7.3 lib/utility_belt/rails_finder_shortcut.rb
akitaonrails-utility_belt-1.0.13 lib/utility_belt/rails_finder_shortcut.rb
utility_belt-1.0.4 lib/rails_finder_shortcut.rb
utility_belt-1.0.0 lib/rails_finder_shortcut.rb
utility_belt-1.0.6 lib/rails_finder_shortcut.rb
utility_belt-1.0.3 lib/rails_finder_shortcut.rb
utility_belt-1.1.0 lib/utility_belt/rails_finder_shortcut.rb
utility_belt-1.0.1 lib/rails_finder_shortcut.rb
utility_belt-1.0.2 lib/rails_finder_shortcut.rb
utility_belt-1.0.5 lib/rails_finder_shortcut.rb