Class: ActiveRecord::DynamicFinderMatch
- Inherits:
-
Object
- Object
- ActiveRecord::DynamicFinderMatch
- Defined in:
- activerecord/lib/active_record/dynamic_finder_match.rb
Overview
Active Record Dynamic Finder Match
Refer to ActiveRecord::Base documentation for Dynamic attribute-based finders for detailed info
Instance Attribute Summary (collapse)
-
- (Object) attribute_names
readonly
Returns the value of attribute attribute_names.
-
- (Object) finder
readonly
Returns the value of attribute finder.
-
- (Object) instantiator
readonly
Returns the value of attribute instantiator.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Boolean) bang?
- - (Boolean) creator?
- - (Boolean) finder?
-
- (DynamicFinderMatch) initialize(finder, instantiator, bang, attribute_names)
constructor
A new instance of DynamicFinderMatch.
- - (Boolean) instantiator?
Constructor Details
- (DynamicFinderMatch) initialize(finder, instantiator, bang, attribute_names)
A new instance of DynamicFinderMatch
31 32 33 34 35 36 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 31 def initialize(finder, instantiator, bang, attribute_names) @finder = finder @instantiator = instantiator @bang = bang @attribute_names = attribute_names end |
Instance Attribute Details
- (Object) attribute_names (readonly)
Returns the value of attribute attribute_names
38 39 40 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 38 def attribute_names @attribute_names end |
- (Object) finder (readonly)
Returns the value of attribute finder
38 39 40 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 38 def finder @finder end |
- (Object) instantiator (readonly)
Returns the value of attribute instantiator
38 39 40 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 38 def instantiator @instantiator end |
Class Method Details
+ (Object) match(method)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 8 def self.match(method) finder = :first bang = false instantiator = nil case method.to_s when /^find_(all_|last_)?by_([_a-zA-Z]\w*)$/ finder = :last if $1 == 'last_' finder = :all if $1 == 'all_' names = $2 when /^find_by_([_a-zA-Z]\w*)\!$/ bang = true names = $1 when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/ instantiator = $1 == 'initialize' ? :new : :create names = $2 else return nil end new(finder, instantiator, bang, names.split('_and_')) end |
Instance Method Details
- (Boolean) bang?
52 53 54 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 52 def bang? @bang end |
- (Boolean) creator?
48 49 50 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 48 def creator? @finder == :first && @instantiator == :create end |
- (Boolean) finder?
40 41 42 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 40 def finder? @finder && !@instantiator end |
- (Boolean) instantiator?
44 45 46 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 44 def instantiator? @finder == :first && @instantiator end |