Class: Showcase::Path::Tree
- Inherits:
-
Struct
- Object
- Struct
- Showcase::Path::Tree
- Defined in:
- app/models/showcase/path.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#id ⇒ Object
Returns the value of attribute id.
-
#root ⇒ Object
(also: #root?)
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #active?(id) ⇒ Boolean
- #edge_for(id) ⇒ Object
-
#initialize(id, children = []) ⇒ Tree
constructor
A new instance of Tree.
- #name ⇒ Object
- #open? ⇒ Boolean
- #ordered_children ⇒ Object
- #ordered_paths ⇒ Object
Constructor Details
#initialize(id, children = []) ⇒ Tree
Returns a new instance of Tree.
3 4 5 |
# File 'app/models/showcase/path.rb', line 3 def initialize(id, children = []) super(id, children, false) end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children
2 3 4 |
# File 'app/models/showcase/path.rb', line 2 def children @children end |
#id ⇒ Object
Returns the value of attribute id
2 3 4 |
# File 'app/models/showcase/path.rb', line 2 def id @id end |
#root ⇒ Object Also known as: root?
Returns the value of attribute root
2 3 4 |
# File 'app/models/showcase/path.rb', line 2 def root @root end |
Class Method Details
Instance Method Details
#active?(id) ⇒ Boolean
20 21 22 |
# File 'app/models/showcase/path.rb', line 20 def active?(id) children.any? { _1.active?(id) } end |
#edge_for(id) ⇒ Object
38 39 40 |
# File 'app/models/showcase/path.rb', line 38 def edge_for(id) find(id) || insert(id) end |
#name ⇒ Object
12 13 14 |
# File 'app/models/showcase/path.rb', line 12 def name id == "." ? "Previews" : id end |
#open? ⇒ Boolean
16 17 18 |
# File 'app/models/showcase/path.rb', line 16 def open? Showcase.tree_opens.call(self) end |
#ordered_children ⇒ Object
24 25 26 |
# File 'app/models/showcase/path.rb', line 24 def ordered_children children.partition { !_1.is_a?(Tree) }.flatten end |
#ordered_paths ⇒ Object
28 29 30 |
# File 'app/models/showcase/path.rb', line 28 def ordered_paths children.flat_map { _1.is_a?(Tree) ? _1.ordered_paths : _1 } end |