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.



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

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

Instance Attribute Details

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#registerObject (readonly)

Returns the value of attribute register.



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

def register
  @register
end

Class Method Details

.from_attributes(attributes, register) ⇒ Object



16
17
18
19
20
21
22
23
24
# 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



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

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



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

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

#to_schemaObject



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

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