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

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

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ AttributeDefinition

Returns a new instance of AttributeDefinition.



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

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

Instance Method Details

#define_on(klass) ⇒ Object



53
54
55
56
57
58
# 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) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
# 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