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



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

#nameObject



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

def name
  @name ||= self.class.name.demodulize
end

#properties_structureObject



19
20
21
# File 'app/components/ninetails/element.rb', line 19

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)


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