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

Instance Method Details

#enumbleEnumbler::Enumble

The Enumble definition that this record defined.

Returns:

Raises:



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_enumSymbol

The enumble graphql_enum if it exists.

Returns:



29
30
31
# File 'lib/enumbler/enabler.rb', line 29

def to_graphql_enum
  to_enumble_attribute(:graphql_enum) || super
end

#to_sString

The enumble label if it exists.

Returns:

  • (String)


35
36
37
# File 'lib/enumbler/enabler.rb', line 35

def to_s
  to_enumble_attribute(:label) || super
end

#to_symSymbol

The enumble symbol if it exists.

Returns:



41
42
43
# File 'lib/enumbler/enabler.rb', line 41

def to_sym
  to_enumble_attribute(:enum) || super
end