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

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

Overview

:nodoc:

Defined Under Namespace

Classes: AttributeMethodMatch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AttributeMethodMatcher

Returns a new instance of AttributeMethodMatcher.



394
395
396
397
398
399
# File 'lib/active_model/attribute_methods.rb', line 394

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

Instance Attribute Details

#method_missing_targetObject (readonly)

Returns the value of attribute method_missing_target.



390
391
392
# File 'lib/active_model/attribute_methods.rb', line 390

def method_missing_target
  @method_missing_target
end

#prefixObject (readonly)

Returns the value of attribute prefix.



390
391
392
# File 'lib/active_model/attribute_methods.rb', line 390

def prefix
  @prefix
end

#suffixObject (readonly)

Returns the value of attribute suffix.



390
391
392
# File 'lib/active_model/attribute_methods.rb', line 390

def suffix
  @suffix
end

Instance Method Details

#match(method_name) ⇒ Object



401
402
403
404
405
# File 'lib/active_model/attribute_methods.rb', line 401

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

#method_name(attr_name) ⇒ Object



407
408
409
# File 'lib/active_model/attribute_methods.rb', line 407

def method_name(attr_name)
  @method_name % attr_name
end

#plain?Boolean

Returns:

  • (Boolean)


411
412
413
# File 'lib/active_model/attribute_methods.rb', line 411

def plain?
  prefix.empty? && suffix.empty?
end