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

#apply_expression_text, #get_association, #get_class_of_snake_model_name, #get_self_object, #snake, #to_bind_models

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_emptyObject (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_moduleObject (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_saveObject (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_objectObject (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

#paramsObject (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_objectObject



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