Module: ActiveRecord::DynamicMatchers::Finder
- Included in:
- FindBy, FindByBang
- Defined in:
- lib/active_record/dynamic_matchers.rb
Instance Method Summary collapse
-
#attributes_hash ⇒ Object
Given that the parameters starts with ‘_`, the finder needs to use the same parameter name.
-
#body ⇒ Object
Extended in activerecord-deprecated_finders.
- #finder ⇒ Object
-
#result ⇒ Object
Extended in activerecord-deprecated_finders.
-
#signature ⇒ Object
The parameters in the signature may have reserved Ruby words, in order to prevent errors, we start each param name with ‘_`.
Instance Method Details
#attributes_hash ⇒ Object
Given that the parameters starts with ‘_`, the finder needs to use the same parameter name.
101 102 103 |
# File 'lib/active_record/dynamic_matchers.rb', line 101 def attributes_hash "{" + attribute_names.map { |name| ":#{name} => _#{name}" }.join(',') + "}" end |
#body ⇒ Object
Extended in activerecord-deprecated_finders
82 83 84 |
# File 'lib/active_record/dynamic_matchers.rb', line 82 def body result end |
#finder ⇒ Object
105 106 107 |
# File 'lib/active_record/dynamic_matchers.rb', line 105 def finder raise NotImplementedError end |
#result ⇒ Object
Extended in activerecord-deprecated_finders
87 88 89 |
# File 'lib/active_record/dynamic_matchers.rb', line 87 def result "#{finder}(#{attributes_hash})" end |
#signature ⇒ Object
The parameters in the signature may have reserved Ruby words, in order to prevent errors, we start each param name with ‘_`.
Extended in activerecord-deprecated_finders
95 96 97 |
# File 'lib/active_record/dynamic_matchers.rb', line 95 def signature attribute_names.map { |name| "_#{name}" }.join(', ') end |