Class: ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher
- Inherits:
-
Object
- Object
- ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher
- Defined in:
- lib/active_model/attribute_methods.rb
Defined Under Namespace
Classes: AttributeMethodMatch
Instance Attribute Summary collapse
-
#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_missing_target ⇒ Object
- #method_name(attr_name) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AttributeMethodMatcher
Returns a new instance of AttributeMethodMatcher.
322 323 324 325 326 |
# File 'lib/active_model/attribute_methods.rb', line 322 def initialize( = {}) .symbolize_keys! @prefix, @suffix = [:prefix] || '', [:suffix] || '' @regex = /^(#{Regexp.escape(@prefix)})(.+?)(#{Regexp.escape(@suffix)})$/ end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
318 319 320 |
# File 'lib/active_model/attribute_methods.rb', line 318 def prefix @prefix end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
318 319 320 |
# File 'lib/active_model/attribute_methods.rb', line 318 def suffix @suffix end |
Instance Method Details
#match(method_name) ⇒ Object
328 329 330 331 332 333 334 |
# File 'lib/active_model/attribute_methods.rb', line 328 def match(method_name) if matchdata = @regex.match(method_name) AttributeMethodMatch.new(method_missing_target, matchdata[2]) else nil end end |
#method_missing_target ⇒ Object
340 341 342 |
# File 'lib/active_model/attribute_methods.rb', line 340 def method_missing_target :"#{prefix}attribute#{suffix}" end |
#method_name(attr_name) ⇒ Object
336 337 338 |
# File 'lib/active_model/attribute_methods.rb', line 336 def method_name(attr_name) "#{prefix}#{attr_name}#{suffix}" end |