Class: FrOData::Schema::EnumType

Inherits:
Object
  • Object
show all
Defined in:
lib/frodata/schema/enum_type.rb

Overview

Enumeration types are nominal types that represent a series of related values. Enumeration types expose these related values as members of the enumeration.

Instance Method Summary collapse

Constructor Details

#initialize(type_definition, schema) ⇒ self

Creates a new EnumType based on the supplied options.

Parameters:



10
11
12
13
# File 'lib/frodata/schema/enum_type.rb', line 10

def initialize(type_definition, schema)
  @type_definition = type_definition
  @schema          = schema
end

Instance Method Details

#[](member_name) ⇒ *

Returns the value of the requested member.

Parameters:

  • member_name (to_s)

Returns:

  • (*)


66
67
68
# File 'lib/frodata/schema/enum_type.rb', line 66

def [](member_name)
  members.invert[member_name.to_s]
end

#is_flags?Boolean

Whether this EnumType supports setting multiple values.

Returns:

  • (Boolean)


29
30
31
# File 'lib/frodata/schema/enum_type.rb', line 29

def is_flags?
  options['IsFlags'] == 'true'
end

#membersHash

Returns the members of this EnumType and their values.

Returns:

  • (Hash)


47
48
49
# File 'lib/frodata/schema/enum_type.rb', line 47

def members
  @members ||= collect_members
end

#nameString

The name of the EnumType

Returns:

  • (String)


17
18
19
# File 'lib/frodata/schema/enum_type.rb', line 17

def name
  options['Name']
end

#namespaceString

Returns the namespace this EnumType belongs to.

Returns:

  • (String)


41
42
43
# File 'lib/frodata/schema/enum_type.rb', line 41

def namespace
  @namespace ||= service.namespace
end

#property_classClass < FrOData::Properties::Enum]

Returns the property class that implements this ‘EnumType`.

Returns:



53
54
55
56
57
58
59
60
61
# File 'lib/frodata/schema/enum_type.rb', line 53

def property_class
  @property_class ||= lambda { |type, members, is_flags|
    klass = Class.new ::FrOData::Properties::Enum
    klass.send(:define_method, :type) { type }
    klass.send(:define_method, :members) { members }
    klass.send(:define_method, :is_flags?) { is_flags }
    klass
  }.call(type, members, is_flags?)
end

#typeString

Returns the namespaced type for the EnumType.

Returns:

  • (String)


23
24
25
# File 'lib/frodata/schema/enum_type.rb', line 23

def type
  "#{namespace}.#{name}"
end

#underlying_typeString

The underlying type of this EnumType.

Returns:

  • (String)


35
36
37
# File 'lib/frodata/schema/enum_type.rb', line 35

def underlying_type
  options['UnderlyingType'] || 'Edm.Int32'
end