Class: ActiveRecord::DynamicMatchers::Method
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | activerecord/lib/active_record/dynamic_matchers.rb |
Class Attribute Summary
- .matchers readonly
Class Method Summary
Instance Attribute Summary
- #attribute_names readonly
- #model readonly
- #name readonly
- #valid? ⇒ Boolean readonly
Instance Method Summary
- #define
-
#attributes_hash
private
Given that the parameters starts with
_
, the finder needs to use the same parameter name. - #body private
- #finder private
-
#signature
private
The parameters in the signature may have reserved Ruby words, in order to prevent errors, we start each param name with
_
.
Constructor Details
.new(model, method_name) ⇒ Method
Class Attribute Details
.matchers (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 30
attr_reader :matchers
Class Method Details
.match(model, name)
[ GitHub ].pattern
[ GitHub ].prefix
# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 41
def prefix raise NotImplementedError end
.suffix
[ GitHub ]# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 45
def suffix "" end
Instance Attribute Details
#attribute_names (readonly)
[ GitHub ]#model (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 50
attr_reader :model, :name, :attribute_names
#name (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 50
attr_reader :model, :name, :attribute_names
#valid? ⇒ Boolean
(readonly)
[ GitHub ]
Instance Method Details
#attributes_hash (private)
Given that the parameters starts with _
, the finder needs to use the same parameter name.
# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 84
def attributes_hash "{" + attribute_names.map { |name| ":#{name} => _#{name}" }.join(",") + "}" end
#body (private)
[ GitHub ]# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 72
def body "#{finder}(#{attributes_hash})" end
#define
[ GitHub ]#finder (private)
# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 88
def finder raise NotImplementedError end
#signature (private)
The parameters in the signature may have reserved Ruby words, in order to prevent errors, we start each param name with _
.
# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 78
def signature attribute_names.map { |name| "_#{name}" }.join(", ") end