Class: SlimFormObject::DataObject
- Inherits:
-
Object
- Object
- SlimFormObject::DataObject
- Includes:
- HelperMethods
- Defined in:
- lib/slim_form_object/data_object.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#form_object ⇒ Object
readonly
Returns the value of attribute form_object.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nested ⇒ Object
Returns the value of attribute nested.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#validator ⇒ Object
readonly
Returns the value of attribute validator.
Instance Method Summary collapse
- #assign_attributes! ⇒ Object
- #associate_with(other_object, force: false) ⇒ Object
- #blank_or_empty?(except_fileds: []) ⇒ Boolean
- #empty_attributes? ⇒ Boolean
-
#initialize(name: nil, attributes: {}, form_object: nil) ⇒ DataObject
constructor
A new instance of DataObject.
- #only_blank_strings_in_attributes? ⇒ Boolean
- #regenerate_object ⇒ Object
Methods included from HelperMethods
#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(name: nil, attributes: {}, form_object: nil) ⇒ DataObject
Returns a new instance of DataObject.
8 9 10 11 12 13 14 15 16 |
# File 'lib/slim_form_object/data_object.rb', line 8 def initialize(name: nil, attributes: {}, form_object: nil) @name = name @model = get_class_of(name, form_object&.base_modules[name&.to_sym]) @attributes = attributes @form_object = form_object @object = make_object @validator = Validator.new(form_object) assign_attributes! end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/slim_form_object/data_object.rb', line 5 def attributes @attributes end |
#form_object ⇒ Object (readonly)
Returns the value of attribute form_object.
5 6 7 |
# File 'lib/slim_form_object/data_object.rb', line 5 def form_object @form_object end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/slim_form_object/data_object.rb', line 5 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/slim_form_object/data_object.rb', line 5 def name @name end |
#nested ⇒ Object
Returns the value of attribute nested.
6 7 8 |
# File 'lib/slim_form_object/data_object.rb', line 6 def nested @nested end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/slim_form_object/data_object.rb', line 5 def object @object end |
#validator ⇒ Object (readonly)
Returns the value of attribute validator.
5 6 7 |
# File 'lib/slim_form_object/data_object.rb', line 5 def validator @validator end |
Instance Method Details
#assign_attributes! ⇒ Object
40 41 42 |
# File 'lib/slim_form_object/data_object.rb', line 40 def assign_attributes! object.assign_attributes(attributes) end |
#associate_with(other_object, force: false) ⇒ Object
18 19 20 21 22 |
# File 'lib/slim_form_object/data_object.rb', line 18 def associate_with(other_object, force: false) return object if ( force and (!object.new_record? and !other_object.new_record?) ) to_bind_models(object, other_object) end |
#blank_or_empty?(except_fileds: []) ⇒ Boolean
24 25 26 |
# File 'lib/slim_form_object/data_object.rb', line 24 def blank_or_empty?(except_fileds: []) validator.blank_or_empty_object?(self, except_fileds: except_fileds) end |
#empty_attributes? ⇒ Boolean
28 29 30 |
# File 'lib/slim_form_object/data_object.rb', line 28 def empty_attributes? validator.empty_attributes?(attributes) end |
#only_blank_strings_in_attributes? ⇒ Boolean
32 33 34 |
# File 'lib/slim_form_object/data_object.rb', line 32 def only_blank_strings_in_attributes? validator.only_blank_strings_in_attributes?(attributes) end |
#regenerate_object ⇒ Object
36 37 38 |
# File 'lib/slim_form_object/data_object.rb', line 36 def regenerate_object @object = make_object end |