Class: Compo::Composites::Parentless
- Inherits:
-
Object
- Object
- Compo::Composites::Parentless
- Includes:
- Composite
- Defined in:
- lib/compo/composites/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
#add, #get_child, #get_child_such_that, #remove_id
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.
29 30 31 |
# File 'lib/compo/composites/parentless.rb', line 29 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.
85 86 87 |
# File 'lib/compo/composites/parentless.rb', line 85 def child_url(_) '' end |
#children ⇒ Hash
Returns the empty hash
56 57 58 |
# File 'lib/compo/composites/parentless.rb', line 56 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.
99 100 101 |
# File 'lib/compo/composites/parentless.rb', line 99 def parent self end |
#remove(child) ⇒ Object
‘Removes’ a child from this Parentless
This always succeeds, and never triggers any other action.
44 45 46 |
# File 'lib/compo/composites/parentless.rb', line 44 def remove(child) child end |
#url ⇒ Hash
Returns the URL of this Parentless
This is always the empty string.
70 71 72 |
# File 'lib/compo/composites/parentless.rb', line 70 def url '' end |