Class: ActionNav::ItemInstance
- Inherits:
-
Object
- Object
- ActionNav::ItemInstance
- Defined in:
- lib/action_nav/item_instance.rb
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #count ⇒ Object
- #description ⇒ Object
- #description? ⇒ Boolean
- #hidden? ⇒ Boolean
- #icon ⇒ Object
- #icon? ⇒ Boolean
- #id ⇒ Object
-
#initialize(base, item) ⇒ ItemInstance
constructor
A new instance of ItemInstance.
- #items ⇒ Object
- #meta ⇒ Object
- #path ⇒ Object
- #title ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(base, item) ⇒ ItemInstance
Returns a new instance of ItemInstance.
8 9 10 11 |
# File 'lib/action_nav/item_instance.rb', line 8 def initialize(base, item) @base = base @item = item end |
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
6 7 8 |
# File 'lib/action_nav/item_instance.rb', line 6 def item @item end |
Instance Method Details
#active? ⇒ Boolean
30 31 32 |
# File 'lib/action_nav/item_instance.rb', line 30 def active? @base.active_path?(*self.path) end |
#count ⇒ Object
72 73 74 |
# File 'lib/action_nav/item_instance.rb', line 72 def count @item.count ? @count ||= @item.count.call : nil end |
#description ⇒ Object
38 39 40 |
# File 'lib/action_nav/item_instance.rb', line 38 def description cache(:description) { parse(@item.description) } end |
#description? ⇒ Boolean
42 43 44 |
# File 'lib/action_nav/item_instance.rb', line 42 def description? !!description end |
#hidden? ⇒ Boolean
62 63 64 65 66 67 68 69 70 |
# File 'lib/action_nav/item_instance.rb', line 62 def hidden? cache(:hidden?) do if @item.hide_unless parse(@item.hide_unless, false) == false else false end end end |
#icon ⇒ Object
54 55 56 |
# File 'lib/action_nav/item_instance.rb', line 54 def icon cache(:icon) { parse(@item.icon) } end |
#icon? ⇒ Boolean
58 59 60 |
# File 'lib/action_nav/item_instance.rb', line 58 def icon? !!icon end |
#id ⇒ Object
13 14 15 |
# File 'lib/action_nav/item_instance.rb', line 13 def id @item.id end |
#items ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/action_nav/item_instance.rb', line 21 def items @item.children.each_with_object([]) do |(_, item), array| instance = ItemInstance.new(@base, item) unless instance.hidden? array << instance end end end |
#meta ⇒ Object
50 51 52 |
# File 'lib/action_nav/item_instance.rb', line 50 def cache(:meta) { parse(@item., {}) } end |
#path ⇒ Object
17 18 19 |
# File 'lib/action_nav/item_instance.rb', line 17 def path @item.path end |
#title ⇒ Object
34 35 36 |
# File 'lib/action_nav/item_instance.rb', line 34 def title cache(:title) { parse(@item.title, ActiveSupport::Inflector.humanize(@item.id.to_s)) } end |
#url ⇒ Object
46 47 48 |
# File 'lib/action_nav/item_instance.rb', line 46 def url cache(:url) { parse(@item.url, "/")} end |