Class: OdataDuty::SchemaBuilder::EnumType

Inherits:
DataType
  • Object
show all
Defined in:
lib/odata_duty/schema_builder/enum_type.rb

Instance Attribute Summary collapse

Attributes inherited from DataType

#_defined_at_, #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

#membersObject (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

#memberObject



13
14
15
# File 'lib/odata_duty/schema_builder/enum_type.rb', line 13

def member(*)
  @members << EnumMember.new(*)
end

#scalar?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/odata_duty/schema_builder/enum_type.rb', line 17

def scalar?
  true
end

#to_oas2Object



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

Raises:



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