# # # # # # # # #
# /49/model_find.rb
#
# by Jan Lelis
# e-mail: mail@janlelis.de
# type/version: ruby
# snippet url: http://rbJL.net/49/model_find.rb
# original post: http://rbJL.net/49-railsrc-rails-console-snippets
# license: CC-BY (DE)
#
# (c) 2011 Jan Lelis.
Dir.glob( File.join(Dir.pwd, *%w<app models ** *.rb>) ).map { |file_name|
table_name = File.basename(file_name).split('.')[0..-2].join
Object.instance_eval do
define_method(table_name) do |*args|
table_class = table_name.camelize.constantize
if args.empty?
table_class
else
table_class.send(:find, *args)
end
end
end
}