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.



12
13
14
# File 'lib/eac_rails_utils/menus/node.rb', line 12

def custom_label
  @custom_label
end

Instance Method Details

#auto_labelString

Returns:

  • (String)


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

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)


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

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)


31
32
33
# File 'lib/eac_rails_utils/menus/node.rb', line 31

def label_translate_key
  parent_label_translate_key
end

#parent_label_translate_keyString

Returns:

  • (String)


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

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