Class: NavigatorRails::Item

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/navigator_rails/item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#active_controllerObject

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_onObject

Returns the value of attribute active_on.



14
15
16
# File 'lib/navigator_rails/item.rb', line 14

def active_on
  @active_on
end

#constraintObject



32
33
34
# File 'lib/navigator_rails/item.rb', line 32

def constraint
  Constraint.process(@constraint.to_s) rescue Store.delete self
end

#contentObject



29
30
31
# File 'lib/navigator_rails/item.rb', line 29

def content
  Decorator.process(@content.to_s) rescue Store.delete self
end

#orderObject

Returns the value of attribute order.



14
15
16
# File 'lib/navigator_rails/item.rb', line 14

def order
  @order
end

#pathObject

Returns the value of attribute path.



14
15
16
# File 'lib/navigator_rails/item.rb', line 14

def path
  @path
end

#typeObject

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

#activeObject



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

#decoratorObject



26
27
28
# File 'lib/navigator_rails/item.rb', line 26

def decorator
  Decorator.for self.type
end

#levelObject



20
21
22
# File 'lib/navigator_rails/item.rb', line 20

def level
  Item.level_of self.path 
end

#relative_pathObject



23
24
25
# File 'lib/navigator_rails/item.rb', line 23

def relative_path
  File.basename path
end

#saveObject



16
17
18
19
# File 'lib/navigator_rails/item.rb', line 16

def save
  self.type ||= Decorator.at level: self.level
  Store.add self
end