Class: SlimFormObject::Validator
- Inherits:
-
Object
- Object
- SlimFormObject::Validator
show all
- Includes:
- HelperMethods
- Defined in:
- lib/slim_form_object/validator.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#assignment_to_each_other, #class_name_if_module, #define_classes_array_with_name, #get_class_of, #get_reflection, #get_self_object, #get_type_and_name_of_association, #iterate_parents_with_nested_objects, #make_constant_name, #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
|
# File 'lib/slim_form_object/validator.rb', line 7
def initialize(form_object)
@form_object = form_object
@data_objects_arr = form_object.data_objects_arr
end
|
Instance Attribute Details
#data_objects_arr ⇒ Object
Returns the value of attribute data_objects_arr.
5
6
7
|
# File 'lib/slim_form_object/validator.rb', line 5
def data_objects_arr
@data_objects_arr
end
|
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
|
Instance Method Details
#allow_object_processing?(data_object) ⇒ Boolean
44
45
46
|
# File 'lib/slim_form_object/validator.rb', line 44
def allow_object_processing?(data_object)
form_object.allow_object_processing_block.call(data_object)
end
|
#allow_to_save_object?(object) ⇒ Boolean
17
18
19
|
# File 'lib/slim_form_object/validator.rb', line 17
def allow_to_save_object?(object)
form_object.allow_to_save_object_block.call(object)
end
|
#allow_to_validate_object?(data_object) ⇒ Boolean
21
22
23
|
# File 'lib/slim_form_object/validator.rb', line 21
def allow_to_validate_object?(data_object)
form_object.allow_to_validate_object_block.call(data_object)
end
|
#blank_or_empty_object?(data_object, except_fileds: []) ⇒ Boolean
39
40
41
42
|
# File 'lib/slim_form_object/validator.rb', line 39
def blank_or_empty_object?(data_object, except_fileds: [])
attributes = data_object.attributes.reject { |key| except_fileds.map{|name| name.to_s }.include?(key.to_s) }
only_blank_or_empty_attributes(attributes) and data_object.nested.empty?
end
|
#empty_attributes?(attributes) ⇒ Boolean
25
26
27
|
# File 'lib/slim_form_object/validator.rb', line 25
def empty_attributes?(attributes)
attributes.empty?
end
|
#only_blank_or_empty_attributes(attributes) ⇒ Object
35
36
37
|
# File 'lib/slim_form_object/validator.rb', line 35
def only_blank_or_empty_attributes(attributes)
empty_attributes?(attributes) or only_blank_strings_in_attributes?(attributes)
end
|
#only_blank_strings_in_attributes?(attributes) ⇒ Boolean
29
30
31
32
33
|
# File 'lib/slim_form_object/validator.rb', line 29
def only_blank_strings_in_attributes?(attributes)
return false if empty_attributes?(attributes)
attributes.each { |key, value| return false if value&.to_s&.strip != '' }
true
end
|
12
13
14
15
|
# File 'lib/slim_form_object/validator.rb', line 12
def validate_form_object
validation_objects(data_objects_arr)
form_object.after_validation_form_block.call(form_object)
end
|