Class: Lutaml::Model::Schema::Decorators::Attribute
- Inherits:
-
Object
- Object
- Lutaml::Model::Schema::Decorators::Attribute
- Defined in:
- lib/lutaml/model/schema/decorators/attribute.rb
Constant Summary collapse
- ATTRIBUTE_TYPES =
{ "string" => ":string", "integer" => ":integer", "boolean" => ":boolean", "number" => ":float", "object" => ":hash", }.freeze
Instance Attribute Summary collapse
-
#base_class ⇒ Object
Returns the value of attribute base_class.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#polymorphic ⇒ Object
readonly
Returns the value of attribute polymorphic.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #choice? ⇒ Boolean
- #collection ⇒ Object
- #collection? ⇒ Boolean
- #default ⇒ Object
-
#initialize(name, options) ⇒ Attribute
constructor
A new instance of Attribute.
- #polymorphic? ⇒ Boolean
- #polymorphic_classes ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Attribute
Returns a new instance of Attribute.
20 21 22 23 24 25 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 20 def initialize(name, ) @name = name = @type = extract_type() @polymorphic = ["oneOf"]&.map { |choice| choice["$ref"].split("/").last } end |
Instance Attribute Details
#base_class ⇒ Object
Returns the value of attribute base_class.
17 18 19 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 17 def base_class @base_class end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 16 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 16 def end |
#polymorphic ⇒ Object (readonly)
Returns the value of attribute polymorphic.
16 17 18 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 16 def polymorphic @polymorphic end |
#type ⇒ Object
Returns the value of attribute type.
17 18 19 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 17 def type @type end |
Instance Method Details
#choice? ⇒ Boolean
61 62 63 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 61 def choice? false end |
#collection ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 47 def collection return unless collection? if ["minItems"] && ["maxItems"] ["minItems"]..["maxItems"] elsif ["minItems"] ["minItems"]..Float::INFINITY elsif ["maxItems"] 0..["maxItems"] else true end end |
#collection? ⇒ Boolean
43 44 45 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 43 def collection? ["type"] == "array" end |
#default ⇒ Object
27 28 29 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 27 def default ["default"] end |
#polymorphic? ⇒ Boolean
31 32 33 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 31 def polymorphic? !!@polymorphic end |
#polymorphic_classes ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 35 def polymorphic_classes return [] unless polymorphic? @base_class.sub_classes.map do |klass| klass.namespaced_name.gsub("_", "::") end end |