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

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

Defined Under Namespace

Classes: AttributeMethodMatch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AttributeMethodMatcher

Returns a new instance of AttributeMethodMatcher.



322
323
324
325
326
# File 'lib/active_model/attribute_methods.rb', line 322

def initialize(options = {})
  options.symbolize_keys!
  @prefix, @suffix = options[:prefix] || '', options[:suffix] || ''
  @regex = /^(#{Regexp.escape(@prefix)})(.+?)(#{Regexp.escape(@suffix)})$/
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



318
319
320
# File 'lib/active_model/attribute_methods.rb', line 318

def prefix
  @prefix
end

#suffixObject (readonly)

Returns the value of attribute suffix.



318
319
320
# File 'lib/active_model/attribute_methods.rb', line 318

def suffix
  @suffix
end

Instance Method Details

#match(method_name) ⇒ Object



328
329
330
331
332
333
334
# File 'lib/active_model/attribute_methods.rb', line 328

def match(method_name)
  if matchdata = @regex.match(method_name)
    AttributeMethodMatch.new(method_missing_target, matchdata[2])
  else
    nil
  end
end

#method_missing_targetObject



340
341
342
# File 'lib/active_model/attribute_methods.rb', line 340

def method_missing_target
  :"#{prefix}attribute#{suffix}"
end

#method_name(attr_name) ⇒ Object



336
337
338
# File 'lib/active_model/attribute_methods.rb', line 336

def method_name(attr_name)
  "#{prefix}#{attr_name}#{suffix}"
end