Class: ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher

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

Overview

:nodoc:

Defined Under Namespace

Classes: AttributeMethodMatch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AttributeMethodMatcher.


485
486
487
488
489
490
491
492
# File 'activemodel/lib/active_model/attribute_methods.rb', line 485

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

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters


481
482
483
# File 'activemodel/lib/active_model/attribute_methods.rb', line 481

def parameters
  @parameters
end

#prefixObject (readonly)

Returns the value of attribute prefix


481
482
483
# File 'activemodel/lib/active_model/attribute_methods.rb', line 481

def prefix
  @prefix
end

#suffixObject (readonly)

Returns the value of attribute suffix


481
482
483
# File 'activemodel/lib/active_model/attribute_methods.rb', line 481

def suffix
  @suffix
end

#targetObject (readonly)

Returns the value of attribute target


481
482
483
# File 'activemodel/lib/active_model/attribute_methods.rb', line 481

def target
  @target
end

Instance Method Details

#match(method_name) ⇒ Object


494
495
496
497
498
# File 'activemodel/lib/active_model/attribute_methods.rb', line 494

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

#method_name(attr_name) ⇒ Object


500
501
502
# File 'activemodel/lib/active_model/attribute_methods.rb', line 500

def method_name(attr_name)
  @method_name % attr_name
end