class ActiveModel::Validations::AcceptanceValidator::AttributeDefinition

Parent:
Object

Attributes

attributes[R]

TODO Change this to private once we've dropped Ruby 2.2 support. Workaround for Ruby 2.2 “private attribute?” warning.

Public Class Methods

new(attributes) Show source
# File activemodel/lib/active_model/validations/acceptance.rb, line 43
def initialize(attributes)
  @attributes = attributes.map(&:to_s)
end

Public Instance Methods

define_on(klass) Show source
# File activemodel/lib/active_model/validations/acceptance.rb, line 52
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) Show source
# File activemodel/lib/active_model/validations/acceptance.rb, line 47
def matches?(method_name)
  attr_name = convert_to_reader_name(method_name)
  attributes.include?(attr_name)
end

© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.