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 |
# File 'lib/navigasmic/core/item.rb', line 24 def highlights_on?(path, params) return false unless @rules.any? params = params.except(*unwanted_keys) !!@rules.detect do |rule| case rule when String path == rule when Regexp path.match(rule) when TrueClass true when FalseClass false when Hash rule.except(*unwanted_keys).detect do |key, value| value = value.gsub(/^\//, '') if key == :controller value == params[key].to_s end else raise ArgumentError, 'Highlighting rules should be an array containing any of/or a Boolean, String, Regexp, Hash or Proc' end end end |
#link? ⇒ Boolean
20 21 22 |
# File 'lib/navigasmic/core/item.rb', line 20 def link? @link.present? && !disabled? end |