Module: Reform::Form::ActiveModel::Validations

Included in:
Validator
Defined in:
lib/reform/form/active_model/validations.rb

Overview

AM::Validations for your form.

Provides ::validates, ::validate, #validate, and #valid?.

Defined Under Namespace

Classes: Validator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/reform/form/active_model/validations.rb', line 10

def self.included(includer)
  includer.instance_eval do
    include Reform::Form::ActiveModel
    inheritable_attr :validator
    self.validator = Class.new(Validator) # the actual validations happen in this instance.

    class << self
      extend Uber::Delegates
      delegates :validator, :validates, :validate, :validates_with, :validate_with

      # Hooray! Delegate translation back to Reform's Validator class which contains AM::Validations.
      delegates :validator, :human_attribute_name, :lookup_ancestors, :i18n_scope # Rails 3.1.
    end
  end
end

Instance Method Details

#build_errorsObject



26
27
28
# File 'lib/reform/form/active_model/validations.rb', line 26

def build_errors
  Reform::Contract::Errors.new(self)
end

#read_attribute_for_validation(name) ⇒ Object

The concept of “composition” has still not arrived in Rails core and they rely on 400 methods being available in one object. This is why we need to provide parts of the I18N API in the form.



32
33
34
# File 'lib/reform/form/active_model/validations.rb', line 32

def read_attribute_for_validation(name)
  send(name)
end