Class: Datapathy::Model::DynamicFinders::ClassMethods::DynamicFinderMatch
- Inherits:
-
Object
- Object
- Datapathy::Model::DynamicFinders::ClassMethods::DynamicFinderMatch
- Defined in:
- lib/datapathy/model/dynamic_finders.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
- #finder? ⇒ Boolean
-
#initialize(method) ⇒ DynamicFinderMatch
constructor
A new instance of DynamicFinderMatch.
- #instantiator? ⇒ Boolean
Constructor Details
#initialize(method) ⇒ DynamicFinderMatch
Returns a new instance of DynamicFinderMatch.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/datapathy/model/dynamic_finders.rb', line 60 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_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.
53 54 55 |
# File 'lib/datapathy/model/dynamic_finders.rb', line 53 def attribute_names @attribute_names end |
#finder ⇒ Object (readonly)
Returns the value of attribute finder.
53 54 55 |
# File 'lib/datapathy/model/dynamic_finders.rb', line 53 def finder @finder end |
#instantiator ⇒ Object (readonly)
Returns the value of attribute instantiator.
53 54 55 |
# File 'lib/datapathy/model/dynamic_finders.rb', line 53 def instantiator @instantiator end |
Class Method Details
.match(method) ⇒ Object
55 56 57 58 |
# File 'lib/datapathy/model/dynamic_finders.rb', line 55 def self.match(method) df_match = self.new(method) df_match.finder ? df_match : nil end |
Instance Method Details
#finder? ⇒ Boolean
76 77 78 |
# File 'lib/datapathy/model/dynamic_finders.rb', line 76 def finder? !@finder.nil? && @instantiator.nil? end |
#instantiator? ⇒ Boolean
80 81 82 |
# File 'lib/datapathy/model/dynamic_finders.rb', line 80 def instantiator? @finder == :first && !@instantiator.nil? end |