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)
-
- (Object) prefix
readonly
Returns the value of attribute prefix.
-
- (Object) suffix
readonly
Returns the value of attribute suffix.
Instance Method Summary (collapse)
-
- (AttributeMethodMatcher) initialize(options = {})
constructor
A new instance of AttributeMethodMatcher.
- - (Object) match(method_name)
- - (Object) method_missing_target
- - (Object) method_name(attr_name)
Constructor Details
- (AttributeMethodMatcher) initialize(options = {})
A new instance of AttributeMethodMatcher
319 320 321 322 323 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 319 def initialize( = {}) .symbolize_keys! @prefix, @suffix = [:prefix] || '', [:suffix] || '' @regex = /^(#{Regexp.escape(@prefix)})(.+?)(#{Regexp.escape(@suffix)})$/ end |
Instance Attribute Details
- (Object) prefix (readonly)
Returns the value of attribute prefix
315 316 317 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 315 def prefix @prefix end |
- (Object) suffix (readonly)
Returns the value of attribute suffix
315 316 317 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 315 def suffix @suffix end |
Instance Method Details
- (Object) match(method_name)
325 326 327 328 329 330 331 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 325 def match(method_name) if matchdata = @regex.match(method_name) AttributeMethodMatch.new(method_missing_target, matchdata[2]) else nil end end |
- (Object) method_missing_target
337 338 339 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 337 def method_missing_target :#{prefix}attribute#{suffix}" end |
- (Object) method_name(attr_name)
333 334 335 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 333 def method_name(attr_name) "#{prefix}#{attr_name}#{suffix}" end |