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.
Class Method Summary collapse
-
.for(item) ⇒ void
Creates a new instance of Parentless and adds an item to it.
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
Class Method Details
.for(item) ⇒ void
This method returns an undefined value.
Creates a new instance of Parentless and adds an item to it
This effectively removes the item’s parent.
If this method is passed nil, then nothing happens.
28 29 30 |
# File 'lib/compo/parentless.rb', line 28 def self.for(item) new.add(nil, item) unless item.nil? end |
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.
84 85 86 |
# File 'lib/compo/parentless.rb', line 84 def child_url(_) '' end |
#children ⇒ Hash
Returns the empty hash
55 56 57 |
# File 'lib/compo/parentless.rb', line 55 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.
98 99 100 |
# File 'lib/compo/parentless.rb', line 98 def parent self end |
#remove(child) ⇒ Object
‘Removes’ a child from this Parentless
This always succeeds, and never triggers any other action.
43 44 45 |
# File 'lib/compo/parentless.rb', line 43 def remove(child) child end |
#url ⇒ Hash
Returns the URL of this Parentless
This is always the empty string.
69 70 71 |
# File 'lib/compo/parentless.rb', line 69 def url '' end |