Class: EacRailsUtils::Menus::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_rails_utils/menus/node.rb

Direct Known Subclasses

Action, Group

Constant Summary collapse

LABEL_TRANSLATE_KEY_PREFIX =
'eac_rails_utils.menus'
TRANSLATE_KEY_SEPARATOR =
'.'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#custom_labelObject

Returns the value of attribute custom_label.



14
15
16
# File 'lib/eac_rails_utils/menus/node.rb', line 14

def custom_label
  @custom_label
end

Instance Method Details

#auto_labelString

Returns:

  • (String)


17
18
19
# File 'lib/eac_rails_utils/menus/node.rb', line 17

def auto_label
  ::I18n.t(label_translate_key)
end

#label(custom_label = nil) ⇒ String, self

Parameters:

  • custom_label (String, nil) (defaults to: nil)

Returns:

  • (String, self)


23
24
25
26
27
28
29
30
# File 'lib/eac_rails_utils/menus/node.rb', line 23

def label(custom_label = nil)
  if custom_label.present?
    self.custom_label = custom_label
    self
  else
    (self.custom_label || auto_label).call_if_proc
  end
end

#label_translate_keyString

Returns:

  • (String)


33
34
35
# File 'lib/eac_rails_utils/menus/node.rb', line 33

def label_translate_key
  parent_label_translate_key
end

#parent_label_translate_keyString

Returns:

  • (String)


38
39
40
41
42
43
# File 'lib/eac_rails_utils/menus/node.rb', line 38

def parent_label_translate_key
  [
    parent_group.if_present(LABEL_TRANSLATE_KEY_PREFIX, &:parent_label_translate_key),
    key
  ].join(TRANSLATE_KEY_SEPARATOR)
end