Class: NavigatorRails::Item
- Inherits:
-
Object
- Object
- NavigatorRails::Item
- Includes:
- ActiveModel::Model
- Defined in:
- lib/navigator_rails/item.rb
Instance Attribute Summary collapse
-
#active_controller ⇒ Object
Returns the value of attribute active_controller.
-
#active_on ⇒ Object
Returns the value of attribute active_on.
- #constraint ⇒ Object
- #content ⇒ Object
-
#order ⇒ Object
Returns the value of attribute order.
-
#path ⇒ Object
Returns the value of attribute path.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #active ⇒ Object
- #children(params = {}) ⇒ Object
- #children_except(params = {}) ⇒ Object
- #decorator ⇒ Object
- #level ⇒ Object
- #relative_path ⇒ Object
- #save ⇒ Object
Instance Attribute Details
#active_controller ⇒ Object
Returns the value of attribute active_controller.
14 15 16 |
# File 'lib/navigator_rails/item.rb', line 14 def active_controller @active_controller end |
#active_on ⇒ Object
Returns the value of attribute active_on.
14 15 16 |
# File 'lib/navigator_rails/item.rb', line 14 def active_on @active_on end |
#constraint ⇒ Object
32 33 34 |
# File 'lib/navigator_rails/item.rb', line 32 def constraint Constraint.process(@constraint.to_s) rescue Store.delete self end |
#content ⇒ Object
29 30 31 |
# File 'lib/navigator_rails/item.rb', line 29 def content Decorator.process(@content.to_s) rescue Store.delete self end |
#order ⇒ Object
Returns the value of attribute order.
14 15 16 |
# File 'lib/navigator_rails/item.rb', line 14 def order @order end |
#path ⇒ Object
Returns the value of attribute path.
14 15 16 |
# File 'lib/navigator_rails/item.rb', line 14 def path @path end |
#type ⇒ Object
Returns the value of attribute type.
14 15 16 |
# File 'lib/navigator_rails/item.rb', line 14 def type @type end |
Class Method Details
.level_of(path) ⇒ Object
5 6 7 |
# File 'lib/navigator_rails/item.rb', line 5 def level_of path path.count('/') end |
.normalize_path(path) ⇒ Object
8 9 10 11 12 |
# File 'lib/navigator_rails/item.rb', line 8 def normalize_path path path = path.to_s path = "/#{path}" unless path =~ /^\// path end |
Instance Method Details
#active ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/navigator_rails/item.rb', line 53 def active return unless @active_on return unless Constraint.process('controller').class == @active_controller return "active" if @active_on == :all return unless Constraint.process('params')['action'].to_sym == @active_on "active" end |
#children(params = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/navigator_rails/item.rb', line 35 def children params={} children = Store.children_of self children.collect do |child| params.each do |attribute,value| child=nil and break unless child and child.send(attribute) == value end child end.compact end |
#children_except(params = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/navigator_rails/item.rb', line 44 def children_except params={} children = Store.children_of self children.collect do |child| params.each do |attribute,value| child=nil and break if child and child.send(attribute) == value end child end.compact end |
#decorator ⇒ Object
26 27 28 |
# File 'lib/navigator_rails/item.rb', line 26 def decorator Decorator.for self.type end |
#level ⇒ Object
20 21 22 |
# File 'lib/navigator_rails/item.rb', line 20 def level Item.level_of self.path end |
#relative_path ⇒ Object
23 24 25 |
# File 'lib/navigator_rails/item.rb', line 23 def relative_path File.basename path end |