Class: ActiveEntity::AMAttributeMethods::ClassMethods::AttributeMethodMatcher
- Inherits:
-
Object
- Object
- ActiveEntity::AMAttributeMethods::ClassMethods::AttributeMethodMatcher
- Defined in:
- lib/active_entity/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
Constructor Details
#initialize(options = {}) ⇒ AttributeMethodMatcher
Returns a new instance of AttributeMethodMatcher.
378 379 380 381 382 383 |
# File 'lib/active_entity/attribute_methods.rb', line 378 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.
374 375 376 |
# File 'lib/active_entity/attribute_methods.rb', line 374 def prefix @prefix end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
374 375 376 |
# File 'lib/active_entity/attribute_methods.rb', line 374 def suffix @suffix end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
374 375 376 |
# File 'lib/active_entity/attribute_methods.rb', line 374 def target @target end |
Instance Method Details
#match(method_name) ⇒ Object
385 386 387 388 389 |
# File 'lib/active_entity/attribute_methods.rb', line 385 def match(method_name) if @regex =~ method_name AttributeMethodMatch.new(target, $1) end end |
#method_name(attr_name) ⇒ Object
391 392 393 |
# File 'lib/active_entity/attribute_methods.rb', line 391 def method_name(attr_name) @method_name % attr_name end |