Class: Lutaml::Model::Schema::Generator::PropertiesCollection

Inherits:
Object
  • Object
show all
Extended by:
SharedMethods
Defined in:
lib/lutaml/model/schema/generator/properties_collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedMethods

extract_register_from

Constructor Details

#initialize(properties = [], register:) ⇒ PropertiesCollection

Returns a new instance of PropertiesCollection.



28
29
30
31
# File 'lib/lutaml/model/schema/generator/properties_collection.rb', line 28

def initialize(properties = [], register:)
  self.properties = properties
  @register = register
end

Instance Attribute Details

#propertiesObject

Returns the value of attribute properties.



26
27
28
# File 'lib/lutaml/model/schema/generator/properties_collection.rb', line 26

def properties
  @properties
end

#registerObject (readonly)

Returns the value of attribute register.



26
27
28
# File 'lib/lutaml/model/schema/generator/properties_collection.rb', line 26

def register
  @register
end

Class Method Details

.from_attributes(attributes, register) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/lutaml/model/schema/generator/properties_collection.rb', line 16

def from_attributes(attributes, register)
  new(register: register).tap do |collection|
    attributes.each do |attribute|
      name = attribute.name
      collection << Property.new(name, attribute, register: register)
    end
  end
end

.from_class(klass) ⇒ Object



12
13
14
# File 'lib/lutaml/model/schema/generator/properties_collection.rb', line 12

def from_class(klass)
  from_attributes(klass.attributes.values, extract_register_from(klass))
end

Instance Method Details

#add_property(property) ⇒ Object Also known as: <<, push



39
40
41
42
43
44
45
# File 'lib/lutaml/model/schema/generator/properties_collection.rb', line 39

def add_property(property)
  @properties << if property.is_a?(Property)
                   property
                 else
                   Property.new(property.name, property, register: register)
                 end
end

#to_schemaObject



33
34
35
36
37
# File 'lib/lutaml/model/schema/generator/properties_collection.rb', line 33

def to_schema
  properties.each_with_object({}) do |property, schema|
    schema.merge!(property.to_schema)
  end
end