Sha256: 9bc7665b9f11dd2c7d7ff3c84b8f1c305b327c1bf3165e2cfcbd6af2bb1ba85a

Contents?: true

Size: 730 Bytes

Versions: 3

Compression:

Stored size: 730 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.
FLYRB_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

3 entries across 3 versions & 1 rubygems

Version Path
flyrb-1.0.0.c lib/flyrb/rails_finder_shortcut.rb
flyrb-1.0.0.b lib/flyrb/rails_finder_shortcut.rb
flyrb-1.0.0.a lib/flyrb/rails_finder_shortcut.rb