Class: Ninetails::Element
- Inherits:
-
Object
- Object
- Ninetails::Element
- Includes:
- PropertyStore
- Defined in:
- app/components/ninetails/element.rb
Instance Method Summary collapse
- #deserialize(input) ⇒ Object
- #name ⇒ Object
- #properties_structure ⇒ Object
- #reference ⇒ Object
-
#valid? ⇒ Boolean
Validate each property_type’s property.
Instance Method Details
#deserialize(input) ⇒ Object
13 14 15 16 17 |
# File 'app/components/ninetails/element.rb', line 13 def deserialize(input) properties_instances.collect do |property| property.serialized_values = input[property.name.to_s] end end |
#name ⇒ Object
9 10 11 |
# File 'app/components/ninetails/element.rb', line 9 def name @name ||= self.class.name.demodulize end |
#properties_structure ⇒ Object
19 20 21 |
# File 'app/components/ninetails/element.rb', line 19 def properties_structure generate_structure.convert_keys(:to_api).with_indifferent_access end |
#reference ⇒ Object
5 6 7 |
# File 'app/components/ninetails/element.rb', line 5 def reference @reference ||= SecureRandom.uuid end |
#valid? ⇒ Boolean
Validate each property_type’s property.
If the property_type doesn’t respond to valid?, then it means it must be a native type, or at least not something which inherits Ninetails::Property, so we will class it as valid blindly.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/components/ninetails/element.rb', line 28 def valid? validations = properties_instances.collect do |property_type| if property_type.property.respond_to?(:valid?) property_type.property.valid? else true end end validations.all? end |