Class: Tienda::NavigationManager
- Inherits:
-
Object
- Object
- Tienda::NavigationManager
- Defined in:
- lib/tienda/navigation_manager.rb
Defined Under Namespace
Classes: NavigationItem
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Class Method Summary collapse
- .build(identifier, &block) ⇒ Object
- .create(identifier) ⇒ Object
- .find(identifier) ⇒ Object
- .managers ⇒ Object
- .render(identifier) ⇒ Object
Instance Method Summary collapse
- #add_item(identifier, options = {}, &block) ⇒ Object
-
#initialize(identifier) ⇒ NavigationManager
constructor
A new instance of NavigationManager.
- #items ⇒ Object
- #remove_item(identifier) ⇒ Object
Constructor Details
#initialize(identifier) ⇒ NavigationManager
Returns a new instance of NavigationManager.
27 28 29 |
# File 'lib/tienda/navigation_manager.rb', line 27 def initialize(identifier) @identifier = identifier end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
25 26 27 |
# File 'lib/tienda/navigation_manager.rb', line 25 def identifier @identifier end |
Class Method Details
.build(identifier, &block) ⇒ Object
11 12 13 14 15 |
# File 'lib/tienda/navigation_manager.rb', line 11 def self.build(identifier, &block) manager = new(identifier.to_s) manager.instance_eval(&block) if block_given? managers << manager end |
.create(identifier) ⇒ Object
7 8 9 |
# File 'lib/tienda/navigation_manager.rb', line 7 def self.create(identifier) managers << new(identifier.to_s) end |
.find(identifier) ⇒ Object
17 18 19 |
# File 'lib/tienda/navigation_manager.rb', line 17 def self.find(identifier) managers.select { |m| m.identifier == identifier.to_s }.first end |
.managers ⇒ Object
3 4 5 |
# File 'lib/tienda/navigation_manager.rb', line 3 def self.managers @managers ||= [] end |
.render(identifier) ⇒ Object
21 22 23 |
# File 'lib/tienda/navigation_manager.rb', line 21 def self.render(identifier) find(identifier).try(:to_html) end |
Instance Method Details
#add_item(identifier, options = {}, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tienda/navigation_manager.rb', line 35 def add_item(identifier, = {}, &block) item = NavigationItem.new item.manager = self item.identifier = identifier.to_s item.url = [:url] if [:url] item. = [:link_options] if [:link_options] item.icon = [:icon] if [:icon] item.active_if = block if block_given? items << item end |
#items ⇒ Object
31 32 33 |
# File 'lib/tienda/navigation_manager.rb', line 31 def items @items ||= [] end |
#remove_item(identifier) ⇒ Object
46 47 48 |
# File 'lib/tienda/navigation_manager.rb', line 46 def remove_item(identifier) items.remote_if { |i| i.identifier.to_s == identifier.to_s } end |