Class: Themis::AR::HasValidationMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/themis/ar/has_validation_method.rb

Overview

Encapsulates implementation of has_validation method.

Instance Method Summary collapse

Constructor Details

#initialize(model_class, names, validation_module, options, block) ⇒ HasValidationMethod

Returns a new instance of HasValidationMethod.

Parameters:

  • model_class (ActiveRecord::Base)
  • names (Symbol)

    names of validation sets

  • validation_module (Module, nil)
  • options (Hash, nil)
  • block (Proc, nil)


11
12
13
14
15
16
17
18
# File 'lib/themis/ar/has_validation_method.rb', line 11

def initialize(model_class, names, validation_module, options, block)
  @model_class = model_class
  @names       = names
  @module      = validation_module
  @default     = options[:default] || false
  @nested      = options[:nested]
  @block       = block
end

Instance Method Details

#execute!Object

Execute the method.



21
22
23
24
25
26
27
28
# File 'lib/themis/ar/has_validation_method.rb', line 21

def execute!
  preinitialize_model_class!
  validate!
  register_validation_sets!
  add_conditional_validators!
  add_after_initialize_hook! if @default
  add_before_validation_hook!
end