Class: FlexibleEnum::IdentityConfigurator

Inherits:
AbstractConfigurator show all
Defined in:
lib/flexible_enum/identity_configurator.rb

Instance Attribute Summary

Attributes inherited from AbstractConfigurator

#attribute_name, #elements, #feature_module, #module_for_elements

Instance Method Summary collapse

Methods inherited from AbstractConfigurator

#add_class_method, #add_instance_method

Instance Method Details

#applyObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/flexible_enum/identity_configurator.rb', line 3

def apply
  configurator = self

  add_instance_method("#{attribute_name}_details") do
    value = send(configurator.attribute_name)
    configurator.details_for(value)
  end

  add_instance_method("#{attribute_name}_name") do
    value = send(configurator.attribute_name)
    configurator.name_for(value)
  end

  add_class_method("human_#{attribute_name}") do |value|
    configurator.human_name_for(value)
  end

  add_instance_method("human_#{attribute_name}") do
    value = send(configurator.attribute_name)
    configurator.human_name_for(value)
  end
end

#details_for(value) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/flexible_enum/identity_configurator.rb', line 34

def details_for(value)
  if value
    element_info(value).try(:last)
  else
    nil
  end
end

#human_name_for(value) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/flexible_enum/identity_configurator.rb', line 42

def human_name_for(value)
  if value
    element_name, element_config = element_info(value)
    element_config[:human_name] || element_name.to_s.humanize
  else
    nil
  end
end

#name_for(value) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/flexible_enum/identity_configurator.rb', line 26

def name_for(value)
  if value
    element_info(value).first.to_s
  else
    nil
  end
end