123456789_123456789_123456789_123456789_123456789_

Class: ActiveModel::Validations::AcceptanceValidator::AttributeDefinition

Relationships & Source Files
Inherits: Object
Defined in: activemodel/lib/active_model/validations/acceptance.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(attributes) ⇒ AttributeDefinition

[ GitHub ]

  
# File 'activemodel/lib/active_model/validations/acceptance.rb', line 45

def initialize(attributes)
  @attributes = attributes.map(&:to_s)
end

Instance Method Details

#define_on(klass)

[ GitHub ]

  
# File 'activemodel/lib/active_model/validations/acceptance.rb', line 54

def define_on(klass)
  attr_readers = attributes.reject { |name| klass.attribute_method?(name) }
  attr_writers = attributes.reject { |name| klass.attribute_method?("#{name}=") }
  klass.send(:attr_reader, *attr_readers)
  klass.send(:attr_writer, *attr_writers)
end

#matches?(method_name) ⇒ Boolean

[ GitHub ]

  
# File 'activemodel/lib/active_model/validations/acceptance.rb', line 49

def matches?(method_name)
  attr_name = convert_to_reader_name(method_name)
  attributes.include?(attr_name)
end