Class: Lutaml::Model::Schema::Decorators::ClassDefinition
- Inherits:
-
Object
- Object
- Lutaml::Model::Schema::Decorators::ClassDefinition
- Defined in:
- lib/lutaml/model/schema/decorators/class_definition.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#base_class ⇒ Object
Returns the value of attribute base_class.
-
#namespaced_name ⇒ Object
readonly
Returns the value of attribute namespaced_name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#sub_classes ⇒ Object
Returns the value of attribute sub_classes.
Instance Method Summary collapse
- #attributes ⇒ Object
- #choice? ⇒ Boolean
-
#initialize(namespaced_name, schema) ⇒ ClassDefinition
constructor
Decorates a JSON schema information to be used in class definitions.
- #name ⇒ Object
- #namespaces ⇒ Object
- #parent_class ⇒ Object
- #polymorphic? ⇒ Boolean
- #polymorphic_attributes ⇒ Object
Constructor Details
#initialize(namespaced_name, schema) ⇒ ClassDefinition
Decorates a JSON schema information to be used in class definitions. This class is used to provide a structured way to handle schema information for class definitions, including attributes, required fields, and JSON mappings.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 21 def initialize(namespaced_name, schema) @namespaced_name = namespaced_name @choices = schema["oneOf"] || [] @additional_properties = schema["additionalProperties"] || false @polymorphic_attributes = [] @properties = (schema["properties"] || {}).to_h do |name, attr| attribute = Decorators::Attribute.new(name, attr) polymorphic_attributes << attribute if attribute.polymorphic? [name, attribute] end @base_class = nil @sub_classes = [] end |
Instance Attribute Details
#additional_properties ⇒ Object (readonly)
Returns the value of attribute additional_properties.
12 13 14 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 12 def additional_properties @additional_properties end |
#base_class ⇒ Object
Returns the value of attribute base_class.
11 12 13 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 11 def base_class @base_class end |
#namespaced_name ⇒ Object (readonly)
Returns the value of attribute namespaced_name.
12 13 14 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 12 def namespaced_name @namespaced_name end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
12 13 14 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 12 def properties @properties end |
#sub_classes ⇒ Object
Returns the value of attribute sub_classes.
11 12 13 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 11 def sub_classes @sub_classes end |
Instance Method Details
#attributes ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 54 def attributes return @properties.values if !choice? choice_attributes = {} @choices.each do |choice| choice["properties"].each do |name, attr| choice_attributes[name] = properties[name] || Decorators::Attribute.new(name, attr) properties[name] = nil if properties[name] end end @properties.values.compact + [Choices.new(choice_attributes)] end |
#choice? ⇒ Boolean
50 51 52 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 50 def choice? @choices&.any? end |
#name ⇒ Object
38 39 40 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 38 def name @name ||= @namespaced_name.split("_").last end |
#namespaces ⇒ Object
42 43 44 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 42 def namespaces @namespaces ||= @namespaced_name.split("_")[0..-2] end |
#parent_class ⇒ Object
46 47 48 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 46 def parent_class @parent_class ||= @base_class&.namespaced_name&.gsub("_", "::") || "Lutaml::Model::Serializable" end |
#polymorphic? ⇒ Boolean
68 69 70 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 68 def polymorphic? polymorphic_attributes.any? end |
#polymorphic_attributes ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/lutaml/model/schema/decorators/class_definition.rb', line 72 def polymorphic_attributes return @polymorphic_attributes if !@polymorphic_attributes.nil? attributes.each do |attr| @polymorphic_attributes << attr if attr.polymorphic? end @polymorphic_attributes end |