Class: OdataDuty::SchemaBuilder::EnumType
- Inherits:
-
DataType
- Object
- DataType
- OdataDuty::SchemaBuilder::EnumType
show all
- Defined in:
- lib/odata_duty/schema_builder/enum_type.rb
Instance Attribute Summary collapse
Attributes inherited from DataType
#_defined_at_, #description, #name
Instance Method Summary
collapse
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
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
30
31
|
# File 'lib/odata_duty/schema_builder/enum_type.rb', line 27
def to_oas2
{ 'type' => 'string', 'enum' => members.map(&:name) }.tap do |hash|
hash['description'] = description if description
end
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
|