Module: Enummer::Extension

Defined in:
lib/enummer/extension.rb

Instance Method Summary collapse

Instance Method Details

#enummer(values) ⇒ Object

Examples:

Defining an enummer with a prefix. This would generate ‘#can_read?`, `#can_read=`, `#can_read!`, `.can_read`, etc.

enummer permissions: %i[read write execute], :_prefix: 'can'

Parameters:

  • values (Hash)

    The attribute name to options mapping for an multi-option enum

Options Hash (values):

  • :_prefix (Boolean|String)

    The prefix to give to generated methods. If true, uses the attribute name.

  • :_suffix (Boolean|String)

    The suffix to give to generated methods. If true, uses the attribute name.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/enummer/extension.rb', line 10

def enummer(values)
  options = {}
  options[:_prefix] = values.delete(:_prefix)
  options[:_suffix] = values.delete(:_suffix)

  name, values = values.first

  attribute(name, :enummer, value_names: values)

  singleton_class.__send__(:define_method, name) { values }

  _enummer_build_with_scope(name, values)
  _enummer_build_values(name, values, options)
end