Class: OdataDuty::SchemaBuilder::ComplexType
- Defined in:
- lib/odata_duty/schema_builder/complex_type.rb
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Attributes inherited from DataType
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ ComplexType
constructor
A new instance of ComplexType.
- #property(name, *args, line__defined__at: caller.first, **kwargs) ⇒ Object
- #to_oas2 ⇒ Object
Methods inherited from DataType
Constructor Details
#initialize(**kwargs) ⇒ ComplexType
Returns a new instance of ComplexType.
9 10 11 12 |
# File 'lib/odata_duty/schema_builder/complex_type.rb', line 9 def initialize(**kwargs) super @properties = [] end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
7 8 9 |
# File 'lib/odata_duty/schema_builder/complex_type.rb', line 7 def properties @properties end |
Instance Method Details
#property(name, *args, line__defined__at: caller.first, **kwargs) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/odata_duty/schema_builder/complex_type.rb', line 14 def property(name, *args, line__defined__at: caller.first, **kwargs) if properties.any? { |p| p.name == name.to_sym } raise PropertyAlreadyDefinedError, "#{name} is already defined" end Property.new(name, *args, line__defined__at: line__defined__at, **kwargs).tap do |property| properties << property end end |
#to_oas2 ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/odata_duty/schema_builder/complex_type.rb', line 24 def to_oas2 { 'type' => 'object', 'properties' => properties.to_h do |property| [property.name.to_s, property.to_oas2] end } end |