Module: ActiveRecord::DynamicMatchers::Finder

Included in:
FindBy, FindByBang
Defined in:
lib/active_record/dynamic_matchers.rb

Instance Method Summary collapse

Instance Method Details

#attributes_hashObject

Given that the parameters starts with `_`, the finder needs to use the same parameter name.


97
98
99
# File 'lib/active_record/dynamic_matchers.rb', line 97

def attributes_hash
  "{" + attribute_names.map { |name| ":#{name} => _#{name}" }.join(',') + "}"
end

#bodyObject

Extended in activerecord-deprecated_finders


78
79
80
# File 'lib/active_record/dynamic_matchers.rb', line 78

def body
  result
end

#finderObject

Raises:

  • (NotImplementedError)

101
102
103
# File 'lib/active_record/dynamic_matchers.rb', line 101

def finder
  raise NotImplementedError
end

#resultObject

Extended in activerecord-deprecated_finders


83
84
85
# File 'lib/active_record/dynamic_matchers.rb', line 83

def result
  "#{finder}(#{attributes_hash})"
end

#signatureObject

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


91
92
93
# File 'lib/active_record/dynamic_matchers.rb', line 91

def signature
  attribute_names.map { |name| "_#{name}" }.join(', ')
end