Class: OdataDuty::SchemaBuilder::EnumType
- Defined in:
- lib/odata_duty/schema_builder/enum_type.rb
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Returns the value of attribute members.
Attributes inherited from DataType
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ EnumType
constructor
A new instance of EnumType.
- #member ⇒ Object
- #scalar? ⇒ Boolean
- #to_oas2 ⇒ Object
- #to_value(val, _context) ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ EnumType
Returns a new instance of EnumType.
8 9 10 11 |
# File 'lib/odata_duty/schema_builder/enum_type.rb', line 8 def initialize(**kwargs) super @members = [] end |
Instance Attribute Details
#members ⇒ Object (readonly)
Returns the value of attribute members.
6 7 8 |
# File 'lib/odata_duty/schema_builder/enum_type.rb', line 6 def members @members end |
Instance Method Details
#member ⇒ Object
13 14 15 |
# File 'lib/odata_duty/schema_builder/enum_type.rb', line 13 def member(*) @members << EnumMember.new(*) end |
#scalar? ⇒ Boolean
17 18 19 |
# File 'lib/odata_duty/schema_builder/enum_type.rb', line 17 def scalar? true end |
#to_oas2 ⇒ Object
27 28 29 |
# File 'lib/odata_duty/schema_builder/enum_type.rb', line 27 def to_oas2 { 'type' => 'string', 'enum' => members.map(&:name) } end |
#to_value(val, _context) ⇒ Object
21 22 23 24 25 |
# File 'lib/odata_duty/schema_builder/enum_type.rb', line 21 def to_value(val, _context) return val if members.map(&:name).include?(val) raise InvalidValue, "#{val} is not a valid member of #{members}" end |