123456789_123456789_123456789_123456789_123456789_

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

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: activemodel/lib/active_model/attribute_methods.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(prefix: "", suffix: "", parameters: nil) ⇒ AttributeMethodPattern

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_methods.rb', line 476

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

Instance Attribute Details

#parameters (readonly)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_methods.rb', line 472

attr_reader :prefix, :suffix, :proxy_target, :parameters

#prefix (readonly)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_methods.rb', line 472

attr_reader :prefix, :suffix, :proxy_target, :parameters

#proxy_target (readonly)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_methods.rb', line 472

attr_reader :prefix, :suffix, :proxy_target, :parameters

#suffix (readonly)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_methods.rb', line 472

attr_reader :prefix, :suffix, :proxy_target, :parameters

Instance Method Details

#match(method_name)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_methods.rb', line 485

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

#method_name(attr_name)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_methods.rb', line 491

def method_name(attr_name)
  @method_name % attr_name
end