Class: SlimFormObject::Validator
- Inherits:
-
Object
- Object
- SlimFormObject::Validator
- Includes:
- HelperMethods
- Defined in:
- lib/slim_form_object/validator.rb
Instance Attribute Summary collapse
-
#array_models_which_not_save_if_empty ⇒ Object
readonly
Returns the value of attribute array_models_which_not_save_if_empty.
-
#base_module ⇒ Object
readonly
Returns the value of attribute base_module.
-
#data_for_save ⇒ Object
readonly
Returns the value of attribute data_for_save.
-
#form_object ⇒ Object
readonly
Returns the value of attribute form_object.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(form_object) ⇒ Validator
constructor
A new instance of Validator.
- #save_if_object_is_empty?(object) ⇒ Boolean
- #validate_form_object ⇒ Object
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_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
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 |