class ActiveModel::Validations::AcceptanceValidator::AttributeDefinition

Attributes

attributes[R]

Public Class Methods

new(attributes) click to toggle source
# File lib/active_model/validations/acceptance.rb, line 44
def initialize(attributes)
  @attributes = attributes.map(&:to_s)
end

Public Instance Methods

define_on(klass) click to toggle source
# File lib/active_model/validations/acceptance.rb, line 53
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) click to toggle source
# File lib/active_model/validations/acceptance.rb, line 48
def matches?(method_name)
  attr_name = convert_to_reader_name(method_name)
  attributes.include?(attr_name)
end

Private Instance Methods

convert_to_reader_name(method_name) click to toggle source
# File lib/active_model/validations/acceptance.rb, line 66
def convert_to_reader_name(method_name)
  method_name.to_s.chomp('=')
end