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
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
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.
394 395 396 397 398 399 |
# File 'lib/active_model/attribute_methods.rb', line 394 def initialize( = {}) @prefix, @suffix = .fetch(:prefix, ""), .fetch(:suffix, "") @regex = /^(?:#{Regexp.escape(@prefix)})(.*)(?:#{Regexp.escape(@suffix)})$/ @target = "#{@prefix}attribute#{@suffix}" @method_name = "#{prefix}%s#{suffix}" end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
390 391 392 |
# File 'lib/active_model/attribute_methods.rb', line 390 def prefix @prefix end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
390 391 392 |
# File 'lib/active_model/attribute_methods.rb', line 390 def suffix @suffix end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
390 391 392 |
# File 'lib/active_model/attribute_methods.rb', line 390 def target @target end |
Instance Method Details
#match(method_name) ⇒ Object
401 402 403 404 405 |
# File 'lib/active_model/attribute_methods.rb', line 401 def match(method_name) if @regex =~ method_name AttributeMethodMatch.new(target, $1) end end |
#method_name(attr_name) ⇒ Object
407 408 409 |
# File 'lib/active_model/attribute_methods.rb', line 407 def method_name(attr_name) @method_name % attr_name end |
#plain? ⇒ Boolean
411 412 413 |
# File 'lib/active_model/attribute_methods.rb', line 411 def plain? prefix.empty? && suffix.empty? end |