Class: Compo::Parentless
- Inherits:
-
Object
- Object
- Compo::Parentless
- Includes:
- Composite
- Defined in:
- lib/compo/parentless.rb
Overview
A Composite that represents the non-existent parent of an orphan
Parentless is the parent assigned when an object is removed from a Composite, and should be the default parent of an object that can be added to one. It exists to make some operations easier, such as URL creation.
Instance Method Summary collapse
-
#child_url(_) ⇒ Hash
Given the ID of a child in this Parentless, returns that child’s URL.
-
#children ⇒ Hash
Returns the empty hash.
-
#parent ⇒ self
Returns the parent of this Parentless.
-
#remove(child) ⇒ Object
‘Removes’ a child from this Parentless.
-
#url ⇒ Hash
Returns the URL of this Parentless.
Methods included from Composite
Instance Method Details
#child_url(_) ⇒ Hash
Given the ID of a child in this Parentless, returns that child’s URL
This is always the empty string. This is so that children of orphan objects have URLs starting with /their_id.
65 66 67 |
# File 'lib/compo/parentless.rb', line 65 def child_url(_) '' end |
#children ⇒ Hash
Returns the empty hash
36 37 38 |
# File 'lib/compo/parentless.rb', line 36 def children {} end |
#parent ⇒ self
Returns the parent of this Parentless
This is always the same Parentless, for convenience’s sake. Technically, as a null object, Parentless has no parent.
79 80 81 |
# File 'lib/compo/parentless.rb', line 79 def parent self end |
#remove(child) ⇒ Object
‘Removes’ a child from this Parentless
This always succeeds, and never triggers any other action.
24 25 26 |
# File 'lib/compo/parentless.rb', line 24 def remove(child) child end |
#url ⇒ Hash
Returns the URL of this Parentless
This is always the empty string.
50 51 52 |
# File 'lib/compo/parentless.rb', line 50 def url '' end |