Class: FrOData::Schema::EnumType
- Inherits:
-
Object
- Object
- FrOData::Schema::EnumType
- 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
-
#[](member_name) ⇒ *
Returns the value of the requested member.
-
#initialize(type_definition, schema) ⇒ self
constructor
Creates a new EnumType based on the supplied options.
-
#is_flags? ⇒ Boolean
Whether this EnumType supports setting multiple values.
-
#members ⇒ Hash
Returns the members of this EnumType and their values.
-
#name ⇒ String
The name of the EnumType.
-
#namespace ⇒ String
Returns the namespace this EnumType belongs to.
-
#property_class ⇒ Class < FrOData::Properties::Enum]
Returns the property class that implements this ‘EnumType`.
-
#type ⇒ String
Returns the namespaced type for the EnumType.
-
#underlying_type ⇒ String
The underlying type of this EnumType.
Constructor Details
#initialize(type_definition, schema) ⇒ self
Creates a new EnumType based on the supplied options.
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.
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.
29 30 31 |
# File 'lib/frodata/schema/enum_type.rb', line 29 def is_flags? ['IsFlags'] == 'true' end |
#members ⇒ Hash
Returns the members of this EnumType and their values.
47 48 49 |
# File 'lib/frodata/schema/enum_type.rb', line 47 def members @members ||= collect_members end |
#name ⇒ String
The name of the EnumType
17 18 19 |
# File 'lib/frodata/schema/enum_type.rb', line 17 def name ['Name'] end |
#namespace ⇒ String
Returns the namespace this EnumType belongs to.
41 42 43 |
# File 'lib/frodata/schema/enum_type.rb', line 41 def namespace @namespace ||= service.namespace end |
#property_class ⇒ Class < FrOData::Properties::Enum]
Returns the property class that implements this ‘EnumType`.
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 |
#type ⇒ String
Returns the namespaced type for the EnumType.
23 24 25 |
# File 'lib/frodata/schema/enum_type.rb', line 23 def type "#{namespace}.#{name}" end |
#underlying_type ⇒ String
The underlying type of this EnumType.
35 36 37 |
# File 'lib/frodata/schema/enum_type.rb', line 35 def ['UnderlyingType'] || 'Edm.Int32' end |