Class: Puffer::Resource::Node
- Inherits:
-
Object
- Object
- Puffer::Resource::Node
- Defined in:
- lib/puffer/resource/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #controller ⇒ Object
- #group ⇒ Object
-
#initialize(*args) ⇒ Node
constructor
A new instance of Node.
- #name ⇒ Object
- #plural ⇒ Object
- #plural? ⇒ Boolean
- #root? ⇒ Boolean
- #scope ⇒ Object
- #singular ⇒ Object
- #singular? ⇒ Boolean
- #to_s ⇒ Object
- #to_struct ⇒ Object
- #url_segment ⇒ Object
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. @parent = args.first @children = [] @parent.children.push self if parent end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
4 5 6 |
# File 'lib/puffer/resource/node.rb', line 4 def children @children end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/puffer/resource/node.rb', line 4 def @options end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/puffer/resource/node.rb', line 4 def parent @parent end |
Instance Method Details
#ancestors ⇒ Object
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 |
#controller ⇒ Object
25 26 27 |
# File 'lib/puffer/resource/node.rb', line 25 def controller [:controller] end |
#group ⇒ Object
29 30 31 |
# File 'lib/puffer/resource/node.rb', line 29 def group controller.configuration.group end |
#name ⇒ Object
13 14 15 |
# File 'lib/puffer/resource/node.rb', line 13 def name [:name] end |
#plural ⇒ Object
41 42 43 |
# File 'lib/puffer/resource/node.rb', line 41 def plural name.to_s.pluralize end |
#plural? ⇒ Boolean
45 46 47 |
# File 'lib/puffer/resource/node.rb', line 45 def plural? !singular? end |
#root? ⇒ Boolean
49 50 51 |
# File 'lib/puffer/resource/node.rb', line 49 def root? parent.nil? end |
#scope ⇒ Object
21 22 23 |
# File 'lib/puffer/resource/node.rb', line 21 def scope [:scope] end |
#singular ⇒ Object
33 34 35 |
# File 'lib/puffer/resource/node.rb', line 33 def singular name.to_s.singularize end |
#singular? ⇒ Boolean
37 38 39 |
# File 'lib/puffer/resource/node.rb', line 37 def singular? [:singular] end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/puffer/resource/node.rb', line 17 def to_s name.to_s end |
#to_struct ⇒ Object
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_segment ⇒ Object
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 |