Module: Enumbler::Enabler
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/enumbler/enabler.rb
Overview
Extending this module bestows the power of the enumbler to the underlying
model. For example, if you have a model Color you would include the
Enabler to support the different colors your Color model represents.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- ENUMBLER_CONFLICT_MESSAGE =
This idea sourced lovingly from ActiveRecord::Enum
<<~TEXT You tried to define the enumble :%<enum>s on the model %<klass>s, but this will generate a %<type>s method `%<method>s`, which is already defined by %<source>s. TEXT
Instance Method Summary collapse
-
#enumble ⇒ Enumbler::Enumble
The Enumble definition that this record defined.
-
#to_graphql_enum ⇒ Symbol
The enumble graphql_enum if it exists.
-
#to_s ⇒ String
The enumble label if it exists.
-
#to_sym ⇒ Symbol
The enumble symbol if it exists.
Instance Method Details
#enumble ⇒ Enumbler::Enumble
The Enumble definition that this record defined.
19 20 21 22 23 24 25 |
# File 'lib/enumbler/enabler.rb', line 19 def enumble @enumble = self.class.find_enumble(id) raise Error, "An enumble is not defined for this record!" if @enumble.nil? @enumble end |
#to_graphql_enum ⇒ Symbol
The enumble graphql_enum if it exists.
29 30 31 |
# File 'lib/enumbler/enabler.rb', line 29 def to_graphql_enum to_enumble_attribute(:graphql_enum) || super end |
#to_s ⇒ String
The enumble label if it exists.
35 36 37 |
# File 'lib/enumbler/enabler.rb', line 35 def to_s to_enumble_attribute(:label) || super end |
#to_sym ⇒ Symbol
The enumble symbol if it exists.
41 42 43 |
# File 'lib/enumbler/enabler.rb', line 41 def to_sym to_enumble_attribute(:enum) || super end |