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, #valid?

Constructor Details

#initialize(form) ⇒ Validator

extend ActiveModel::Naming



39
40
41
# File 'lib/reform/form/active_model/validations.rb', line 39

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



43
44
45
# File 'lib/reform/form/active_model/validations.rb', line 43

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?



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

def self.clone
  Class.new(self)
end

.model_nameObject

def self.model_name # FIXME: this is only needed for i18n, it seems.

"Reform::Form"

end



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

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