Class: Apia::Enum

Inherits:
Object
  • Object
show all
Extended by:
Defineable
Defined in:
lib/apia/enum.rb

Direct Known Subclasses

Schema::RequestMethodEnum

Class Method Summary collapse

Methods included from Defineable

create, inspect, method_missing, name, respond_to_missing?

Class Method Details

.cast(value = nil, &block) ⇒ Object?

Cast a value or define a new block for casting (for DSL purposes)

Parameters:

  • value (Object?) (defaults to: nil)

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/apia/enum.rb', line 26

def cast(value = nil, &block)
  if block_given? && value.nil?
    return definition.dsl.cast(&block)
  end

  value = definition.cast.call(value) if definition.cast

  if definition.values[value].nil?
    raise InvalidEnumOptionError.new(self, value)
  end

  value
end

.definitionApia::Definitions::Enum

Return the definition object for the enum



18
19
20
# File 'lib/apia/enum.rb', line 18

def definition
  @definition ||= Definitions::Enum.new(Helpers.class_name_to_id(name))
end