Module: Compo::UrlReferenceable
- Included in:
- ArrayBranch, HashBranch, Leaf
- Defined in:
- lib/compo/url_referenceable.rb
Overview
Adds ID-based ‘URL’s to Compo classes
For the purposes of this module, a URL is a string of slash-delimited IDs representing the location of a Composite in the tree structure formed by its ancestors. Depending on the types of IDs used in the structure, the URLs may not actually be literal Uniform Resource Locators.
This module expects its includer to define #parent and #id. These are defined, for example, by the Compo::ParentTracker mixin.
Instance Method Summary collapse
-
#parent_url ⇒ String
Returns the URL of this object’s parent.
-
#url ⇒ String
Returns the URL of this object.
Instance Method Details
#parent_url ⇒ String
Returns the URL of this object’s parent
45 46 47 |
# File 'lib/compo/url_referenceable.rb', line 45 def parent_url parent.nil? ? nil : parent.url end |
#url ⇒ String
Returns the URL of this object
The #url of a Composite is defined inductively as ” for composites that have no parent, and the joining of the parent URL and the current ID otherwise.
The result of #url can be used to give a URL hierarchy to Composites.
29 30 31 |
# File 'lib/compo/url_referenceable.rb', line 29 def url parent.nil? ? '' : [parent_url, id].join('/') end |