Class: Reform::Form::ActiveModel::Validations::Validator

Inherits:
Object
  • Object
show all
Includes:
Reform::Form::ActiveModel::Validations
Defined in:
lib/reform/form/active_model/validations.rb

Overview

Validators is the validatable object. On the class level, we define validations, on instance, it exposes #valid?.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Reform::Form::ActiveModel::Validations

#build_errors, included, #read_attribute_for_validation, #valid?

Constructor Details

#initialize(form) ⇒ Validator

extend ActiveModel::Naming



51
52
53
# File 'lib/reform/form/active_model/validations.rb', line 51

def initialize(form)
  @form = form
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



55
56
57
# File 'lib/reform/form/active_model/validations.rb', line 55

def method_missing(method_name, *args, &block)
  @form.send(method_name, *args, &block)
end

Class Method Details

.cloneObject

we can also do self.name and return “reform/form” but then run into “wrong constant name reform/form” from the autoloader. wtf?



64
65
66
# File 'lib/reform/form/active_model/validations.rb', line 64

def self.clone
  Class.new(self)
end

.model_nameObject



59
60
61
# File 'lib/reform/form/active_model/validations.rb', line 59

def self.model_name
  ActiveModel::Name.new(Reform::Form)
end