Class: ActiveModel::AttributeMethods::ClassMethods::AttributeMethodPattern

Inherits:
Object
  • Object
show all
Defined in:
activemodel/lib/active_model/attribute_methods.rb

Overview

:nodoc:

Defined Under Namespace

Classes: AttributeMethod

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix: "", suffix: "", parameters: nil) ⇒ AttributeMethodPattern

Returns a new instance of AttributeMethodPattern.


426
427
428
429
430
431
432
433
# File 'activemodel/lib/active_model/attribute_methods.rb', line 426

def initialize(prefix: "", suffix: "", parameters: nil)
  @prefix = prefix
  @suffix = suffix
  @parameters = parameters.nil? ? FORWARD_PARAMETERS : parameters
  @regex = /^(?:#{Regexp.escape(@prefix)})(.*)(?:#{Regexp.escape(@suffix)})$/
  @proxy_target = "#{@prefix}attribute#{@suffix}"
  @method_name = "#{prefix}%s#{suffix}"
end

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.


422
423
424
# File 'activemodel/lib/active_model/attribute_methods.rb', line 422

def parameters
  @parameters
end

#prefixObject (readonly)

Returns the value of attribute prefix.


422
423
424
# File 'activemodel/lib/active_model/attribute_methods.rb', line 422

def prefix
  @prefix
end

#proxy_targetObject (readonly)

Returns the value of attribute proxy_target.


422
423
424
# File 'activemodel/lib/active_model/attribute_methods.rb', line 422

def proxy_target
  @proxy_target
end

#suffixObject (readonly)

Returns the value of attribute suffix.


422
423
424
# File 'activemodel/lib/active_model/attribute_methods.rb', line 422

def suffix
  @suffix
end

Instance Method Details

#match(method_name) ⇒ Object


435
436
437
438
439
# File 'activemodel/lib/active_model/attribute_methods.rb', line 435

def match(method_name)
  if @regex =~ method_name
    AttributeMethod.new(proxy_target, $1)
  end
end

#method_name(attr_name) ⇒ Object


441
442
443
# File 'activemodel/lib/active_model/attribute_methods.rb', line 441

def method_name(attr_name)
  @method_name % attr_name
end