Class: ActiveRecord::DynamicFinderMatch
- Inherits:
-
Object
- Object
- ActiveRecord::DynamicFinderMatch
- Defined in:
- lib/gems/activerecord-2.2.2/lib/active_record/dynamic_finder_match.rb
Instance Attribute Summary collapse
-
#attribute_names ⇒ Object
readonly
Returns the value of attribute attribute_names.
-
#finder ⇒ Object
readonly
Returns the value of attribute finder.
-
#instantiator ⇒ Object
readonly
Returns the value of attribute instantiator.
Class Method Summary collapse
Instance Method Summary collapse
- #bang? ⇒ Boolean
- #finder? ⇒ Boolean
-
#initialize(method) ⇒ DynamicFinderMatch
constructor
A new instance of DynamicFinderMatch.
- #instantiator? ⇒ Boolean
Constructor Details
#initialize(method) ⇒ DynamicFinderMatch
Returns a new instance of DynamicFinderMatch.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gems/activerecord-2.2.2/lib/active_record/dynamic_finder_match.rb', line 8 def initialize(method) @finder = :first 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
#attribute_names ⇒ Object (readonly)
Returns the value of attribute attribute_names.
27 28 29 |
# File 'lib/gems/activerecord-2.2.2/lib/active_record/dynamic_finder_match.rb', line 27 def attribute_names @attribute_names end |
#finder ⇒ Object (readonly)
Returns the value of attribute finder.
27 28 29 |
# File 'lib/gems/activerecord-2.2.2/lib/active_record/dynamic_finder_match.rb', line 27 def finder @finder end |
#instantiator ⇒ Object (readonly)
Returns the value of attribute instantiator.
27 28 29 |
# File 'lib/gems/activerecord-2.2.2/lib/active_record/dynamic_finder_match.rb', line 27 def instantiator @instantiator end |
Class Method Details
.match(method) ⇒ Object
3 4 5 6 |
# File 'lib/gems/activerecord-2.2.2/lib/active_record/dynamic_finder_match.rb', line 3 def self.match(method) df_match = self.new(method) df_match.finder ? df_match : nil end |
Instance Method Details
#bang? ⇒ Boolean
37 38 39 |
# File 'lib/gems/activerecord-2.2.2/lib/active_record/dynamic_finder_match.rb', line 37 def bang? @bang end |
#finder? ⇒ Boolean
29 30 31 |
# File 'lib/gems/activerecord-2.2.2/lib/active_record/dynamic_finder_match.rb', line 29 def finder? !@finder.nil? && @instantiator.nil? end |
#instantiator? ⇒ Boolean
33 34 35 |
# File 'lib/gems/activerecord-2.2.2/lib/active_record/dynamic_finder_match.rb', line 33 def instantiator? @finder == :first && !@instantiator.nil? end |