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 26 27 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 20 def initialize(name, ) @name = name @options = @type = extract_type() @polymorphic = ["oneOf"]&.map do |choice| choice["$ref"].split("/").last end 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 @options 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
63 64 65 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 63 def choice? false end |
#collection ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 49 def collection return unless collection? if @options["minItems"] && @options["maxItems"] @options["minItems"]..@options["maxItems"] elsif @options["minItems"] @options["minItems"]..Float::INFINITY elsif @options["maxItems"] 0..@options["maxItems"] else true end end |
#collection? ⇒ Boolean
45 46 47 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 45 def collection? @options["type"] == "array" end |
#default ⇒ Object
29 30 31 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 29 def default @options["default"] end |
#polymorphic? ⇒ Boolean
33 34 35 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 33 def polymorphic? !!@polymorphic end |
#polymorphic_classes ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/lutaml/model/schema/decorators/attribute.rb', line 37 def polymorphic_classes return [] unless polymorphic? @base_class.sub_classes.map do |klass| klass.namespaced_name.gsub("_", "::") end end |