Class: Apia::Enum
Direct Known Subclasses
Class Method Summary collapse
-
.cast(value = nil, &block) ⇒ Object?
Cast a value or define a new block for casting (for DSL purposes).
-
.definition ⇒ Apia::Definitions::Enum
Return the definition object for the enum.
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)
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 |
.definition ⇒ Apia::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 |