Class: Lutaml::Model::Schema::Generator::PropertiesCollection
- Inherits:
-
Object
- Object
- Lutaml::Model::Schema::Generator::PropertiesCollection
- Extended by:
- SharedMethods
- Defined in:
- lib/lutaml/model/schema/generator/properties_collection.rb
Instance Attribute Summary collapse
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#register ⇒ Object
readonly
Returns the value of attribute register.
Class Method Summary collapse
Instance Method Summary collapse
- #add_property(property) ⇒ Object (also: #<<, #push)
-
#initialize(properties = [], register:) ⇒ PropertiesCollection
constructor
A new instance of PropertiesCollection.
- #to_schema ⇒ Object
Methods included from SharedMethods
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
#properties ⇒ Object
Returns the value of attribute properties.
26 27 28 |
# File 'lib/lutaml/model/schema/generator/properties_collection.rb', line 26 def properties @properties end |
#register ⇒ Object (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_schema ⇒ Object
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 |