Class: SlimFormObject::Validator

Inherits:
Object
  • Object
show all
Includes:
HelperMethods
Defined in:
lib/slim_form_object/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HelperMethods

#assignment_to_each_other, #class_name_if_module, #get_class_of, #get_reflection, #get_self_object, #get_type_and_name_of_association, #method_name_association, #snake, #to_bind_models, #type_and_name_of_association_back_and_forth, #type_association

Constructor Details

#initialize(form_object) ⇒ Validator

Returns a new instance of Validator.



7
8
9
10
11
12
13
# File 'lib/slim_form_object/validator.rb', line 7

def initialize(form_object)
  @form_object                          = form_object
  @base_module                          = form_object.class.base_module
  @params                               = form_object.params
  @data_for_save                        = form_object.data_for_save
  @array_models_which_not_save_if_empty = form_object.array_models_which_not_save_if_empty
end

Instance Attribute Details

#array_models_which_not_save_if_empty ⇒ Object (readonly)

Returns the value of attribute array_models_which_not_save_if_empty.



5
6
7
# File 'lib/slim_form_object/validator.rb', line 5

def array_models_which_not_save_if_empty
  @array_models_which_not_save_if_empty
end

#base_module ⇒ Object (readonly)

Returns the value of attribute base_module.



5
6
7
# File 'lib/slim_form_object/validator.rb', line 5

def base_module
  @base_module
end

#data_for_save ⇒ Object (readonly)

Returns the value of attribute data_for_save.



5
6
7
# File 'lib/slim_form_object/validator.rb', line 5

def data_for_save
  @data_for_save
end

#form_object ⇒ Object (readonly)

Returns the value of attribute form_object.



5
6
7
# File 'lib/slim_form_object/validator.rb', line 5

def form_object
  @form_object
end

#params ⇒ Object (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/slim_form_object/validator.rb', line 5

def params
  @params
end

Instance Method Details

#save_if_object_is_empty?(object) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/slim_form_object/validator.rb', line 21

def save_if_object_is_empty?(object)
  !(all_attributes_is_nil?(object) and array_models_which_not_save_if_empty.include?(object.class))
end

#validate_form_object ⇒ Object



15
16
17
18
19
# File 'lib/slim_form_object/validator.rb', line 15

def validate_form_object
  form_object.before_validation_block.call(form_object)
  validation_objects(data_for_save)
  form_object.after_validation_block.call(form_object)
end