Class: Navigasmic::Item
- Inherits:
-
Object
- Object
- Navigasmic::Item
- Defined in:
- lib/navigasmic/core/item.rb
Instance Attribute Summary collapse
-
#link ⇒ Object
Returns the value of attribute link.
Instance Method Summary collapse
- #disabled? ⇒ Boolean
- #hidden? ⇒ Boolean
- #highlights_on?(path, params) ⇒ Boolean
-
#initialize(label, link, visible, options = {}) ⇒ Item
constructor
A new instance of Item.
- #link? ⇒ Boolean
Constructor Details
#initialize(label, link, visible, options = {}) ⇒ Item
Returns a new instance of Item.
4 5 6 7 8 9 10 |
# File 'lib/navigasmic/core/item.rb', line 4 def initialize(label, link, visible, = {}) @label, @link, @visible = label, link, visible @disabled = .delete(:disabled_if) .delete(:hidden_unless) @rules = calculate_highlighting_rules(.delete(:highlights_on)) end |
Instance Attribute Details
#link ⇒ Object
Returns the value of attribute link.
3 4 5 |
# File 'lib/navigasmic/core/item.rb', line 3 def link @link end |
Instance Method Details
#disabled? ⇒ Boolean
16 17 18 |
# File 'lib/navigasmic/core/item.rb', line 16 def disabled? @disabled end |
#hidden? ⇒ Boolean
12 13 14 |
# File 'lib/navigasmic/core/item.rb', line 12 def hidden? !@visible end |
#highlights_on?(path, params) ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/navigasmic/core/item.rb', line 24 def highlights_on?(path, params) params = clean_unwanted_keys(params) result = false @rules.each do |rule| highlighted = true case rule when String then highlighted &= path == rule when Regexp then highlighted &= path.match(rule) when TrueClass then highlighted &= rule when FalseClass then highlighted &= rule when Hash clean_unwanted_keys(rule).each do |key, value| value.gsub!(/^\//, '') if key == :controller highlighted &= value == params[key].to_s end else raise 'highlighting rules should be an array containing any of/or a Boolean, String, Regexp, Hash or Proc' end result |= highlighted end result end |
#link? ⇒ Boolean
20 21 22 |
# File 'lib/navigasmic/core/item.rb', line 20 def link? @link.present? && !disabled? end |