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(method)
constructor
A new instance of DynamicFinderMatch.
- - (Boolean) instantiator?
Constructor Details
- (DynamicFinderMatch) initialize(method)
A new instance of DynamicFinderMatch
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 13 def initialize(method) @finder = :first @bang = false @instantiator = nil case method.to_s when /^find_(all_by|last_by|by)_([_a-zA-Z]\w*)$/ @finder = :last if $1 == 'last_by' @finder = :all if $1 == 'all_by' 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 @finder = nil end @attribute_names = names && names.split('_and_') end |
Instance Attribute Details
- (Object) attribute_names (readonly)
Returns the value of attribute attribute_names
35 36 37 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 35 def attribute_names @attribute_names end |
- (Object) finder (readonly)
Returns the value of attribute finder
35 36 37 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 35 def finder @finder end |
- (Object) instantiator (readonly)
Returns the value of attribute instantiator
35 36 37 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 35 def instantiator @instantiator end |
Class Method Details
+ (Object) match(method)
8 9 10 11 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 8 def self.match(method) df_match = self.new(method) df_match.finder ? df_match : nil end |
Instance Method Details
- (Boolean) bang?
49 50 51 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 49 def bang? @bang end |
- (Boolean) creator?
45 46 47 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 45 def creator? @finder == :first && @instantiator == :create end |
- (Boolean) finder?
37 38 39 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 37 def finder? !@finder.nil? && @instantiator.nil? end |
- (Boolean) instantiator?
41 42 43 |
# File 'activerecord/lib/active_record/dynamic_finder_match.rb', line 41 def instantiator? @finder == :first && !@instantiator.nil? end |