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
24
# 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
  values = _enummer_determine_bit_pairs(values)

  attribute(name, :enummer, values: values)

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

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