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
-
#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
- #plain? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ AttributeMethodMatcher
Returns a new instance of AttributeMethodMatcher.
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/active_model/attribute_methods.rb', line 355 def initialize( = {}) .symbolize_keys! if [:prefix] == '' || [:suffix] == '' ActiveSupport::Deprecation.warn( "Specifying an empty prefix/suffix for an attribute method is no longer " \ "necessary. If the un-prefixed/suffixed version of the method has not been " \ "defined when `define_attribute_methods` is called, it will be defined " \ "automatically." ) end @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.
351 352 353 |
# File 'lib/active_model/attribute_methods.rb', line 351 def method_missing_target @method_missing_target end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
351 352 353 |
# File 'lib/active_model/attribute_methods.rb', line 351 def prefix @prefix end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
351 352 353 |
# File 'lib/active_model/attribute_methods.rb', line 351 def suffix @suffix end |
Instance Method Details
#match(method_name) ⇒ Object
373 374 375 376 377 378 379 |
# File 'lib/active_model/attribute_methods.rb', line 373 def match(method_name) if @regex =~ method_name AttributeMethodMatch.new(method_missing_target, $2, method_name) else nil end end |
#method_name(attr_name) ⇒ Object
381 382 383 |
# File 'lib/active_model/attribute_methods.rb', line 381 def method_name(attr_name) @method_name % attr_name end |
#plain? ⇒ Boolean
385 386 387 |
# File 'lib/active_model/attribute_methods.rb', line 385 def plain? prefix.empty? && suffix.empty? end |