Active Record Dynamic Finder Match
Refer to ActiveRecord::Base documentation for Dynamic attribute-based finders for detailed info
Methods
- B
- C
- F
- I
- M
- N
- S
Attributes
[R] | finder | |
[R] | attribute_names | |
[R] | instantiator |
Class Public methods
# File activerecord/lib/active_record/dynamic_finder_match.rb, line 8 8: def self.match(method) 9: finder = :first 10: bang = false 11: instantiator = nil 12: 13: case method.to_s 14: when /^find_(all_|last_)?by_([_a-zA-Z]\w*)$/ 15: finder = :last if $1 == 'last_' 16: finder = :all if $1 == 'all_' 17: names = $2 18: when /^find_by_([_a-zA-Z]\w*)\!$/ 19: bang = true 20: names = $1 21: when /^find_or_create_by_([_a-zA-Z]\w*)\!$/ 22: bang = true 23: instantiator = :create 24: names = $1 25: when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/ 26: instantiator = $1 == 'initialize' ? :new : :create 27: names = $2 28: else 29: return nil 30: end 31: 32: new(finder, instantiator, bang, names.split('_and_')) 33: end
Instance Public methods