Class: ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher
- Inherits:
-
Object
- Object
- ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher
- Defined in:
- lib/active_model/attribute_methods.rb
Overview
:nodoc:
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.
392 393 394 395 396 397 |
# File 'lib/active_model/attribute_methods.rb', line 392 def initialize( = {}) @prefix, @suffix = .fetch(:prefix, ""), .fetch(: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.
388 389 390 |
# File 'lib/active_model/attribute_methods.rb', line 388 def method_missing_target @method_missing_target end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
388 389 390 |
# File 'lib/active_model/attribute_methods.rb', line 388 def prefix @prefix end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
388 389 390 |
# File 'lib/active_model/attribute_methods.rb', line 388 def suffix @suffix end |
Instance Method Details
#match(method_name) ⇒ Object
399 400 401 402 403 |
# File 'lib/active_model/attribute_methods.rb', line 399 def match(method_name) if @regex =~ method_name AttributeMethodMatch.new(method_missing_target, $1, method_name) end end |
#method_name(attr_name) ⇒ Object
405 406 407 |
# File 'lib/active_model/attribute_methods.rb', line 405 def method_name(attr_name) @method_name % attr_name end |
#plain? ⇒ Boolean
409 410 411 |
# File 'lib/active_model/attribute_methods.rb', line 409 def plain? prefix.empty? && suffix.empty? end |