Class: ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher
- Inherits:
-
Object
- Object
- ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher
- Defined in:
- activemodel/lib/active_model/attribute_methods.rb
Defined Under Namespace
Classes: AttributeMethodMatch
Instance Attribute Summary collapse
-
#method_missing_target ⇒ Object
readonly
Returns the value of attribute method_missing_target.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ AttributeMethodMatcher
constructor
A new instance of AttributeMethodMatcher.
- #match(method_name) ⇒ Object
- #method_name(attr_name) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AttributeMethodMatcher
Returns a new instance of AttributeMethodMatcher.
346 347 348 349 350 351 352 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 346 def initialize( = {}) .symbolize_keys! @prefix, @suffix = [:prefix] || '', [:suffix] || '' @regex = /^(#{Regexp.escape(@prefix)})(.+?)(#{Regexp.escape(@suffix)})$/ @method_missing_target = "#{@prefix}attribute#{@suffix}" @method_name = "#{prefix}%s#{suffix}" end |
Instance Attribute Details
#method_missing_target ⇒ Object (readonly)
Returns the value of attribute method_missing_target
342 343 344 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 342 def method_missing_target @method_missing_target end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix
342 343 344 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 342 def prefix @prefix end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix
342 343 344 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 342 def suffix @suffix end |
Instance Method Details
#match(method_name) ⇒ Object
354 355 356 357 358 359 360 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 354 def match(method_name) if @regex =~ method_name AttributeMethodMatch.new(method_missing_target, $2) else nil end end |
#method_name(attr_name) ⇒ Object
362 363 364 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 362 def method_name(attr_name) @method_name % attr_name end |