Class: Ninetails::Element

Inherits:
Object
  • Object
show all
Includes:
PropertyStore
Defined in:
app/components/ninetails/element.rb

Instance Method Summary collapse

Instance Method Details

#deserialize(input) ⇒ Object



9
10
11
12
13
# File 'app/components/ninetails/element.rb', line 9

def deserialize(input)
  properties_instances.collect do |property|
    property.serialized_values = input[property.name.to_s]
  end
end

#properties_structureObject



15
16
17
# File 'app/components/ninetails/element.rb', line 15

def properties_structure
  generate_structure.convert_keys(:to_api).with_indifferent_access
end

#referenceObject



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.

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
# File 'app/components/ninetails/element.rb', line 24

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