Class: Puffer::Resource::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/puffer/resource/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Node

Returns a new instance of Node.



6
7
8
9
10
11
# File 'lib/puffer/resource/node.rb', line 6

def initialize *args
  @options = args.extract_options!
  @parent = args.first
  @children = []
  @parent.children.push self if parent
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



4
5
6
# File 'lib/puffer/resource/node.rb', line 4

def children
  @children
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/puffer/resource/node.rb', line 4

def options
  @options
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/puffer/resource/node.rb', line 4

def parent
  @parent
end

Instance Method Details

#ancestorsObject



53
54
55
56
57
58
59
60
# File 'lib/puffer/resource/node.rb', line 53

def ancestors
  ancestors = []
  resource = self
  while resource = resource.parent do
    ancestors.unshift resource
  end
  ancestors
end

#controllerObject



25
26
27
# File 'lib/puffer/resource/node.rb', line 25

def controller
  options[:controller]
end

#groupObject



29
30
31
# File 'lib/puffer/resource/node.rb', line 29

def group
  controller.configuration.group
end

#nameObject



13
14
15
# File 'lib/puffer/resource/node.rb', line 13

def name
  options[:name]
end

#pluralObject



41
42
43
# File 'lib/puffer/resource/node.rb', line 41

def plural
  name.to_s.pluralize
end

#plural?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/puffer/resource/node.rb', line 45

def plural?
  !singular?
end

#root?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/puffer/resource/node.rb', line 49

def root?
  parent.nil?
end

#scopeObject



21
22
23
# File 'lib/puffer/resource/node.rb', line 21

def scope
  options[:scope]
end

#singularObject



33
34
35
# File 'lib/puffer/resource/node.rb', line 33

def singular
  name.to_s.singularize
end

#singular?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/puffer/resource/node.rb', line 37

def singular?
  options[:singular]
end

#to_sObject



17
18
19
# File 'lib/puffer/resource/node.rb', line 17

def to_s
  name.to_s
end

#to_structObject



66
67
68
# File 'lib/puffer/resource/node.rb', line 66

def to_struct
  {:scope => scope, :current => name, :children => children.map(&:name), :ancestors => ancestors.map(&:name)}
end

#url_segmentObject



62
63
64
# File 'lib/puffer/resource/node.rb', line 62

def url_segment
  [name, (:index if singular == plural)].compact.map(&:to_s).join('_')
end