Class: Compo::Finders::Url
- Inherits:
-
Object
- Object
- Compo::Finders::Url
- Defined in:
- lib/compo/finders/url.rb
Overview
A method object for finding an item in a composite tree via its URL
These are not thread-safe.
Class Method Summary collapse
-
.find(*args) {|resource, args| ... } ⇒ Object
Finds the model object at a URL, given a model root.
Instance Method Summary collapse
-
#initialize(root, url, missing_proc: nil) ⇒ Url
constructor
Initialises an URL finder.
-
#run {|resource, args| ... } ⇒ Object
Attempts to find a child resource with the given partial URL.
Constructor Details
Class Method Details
.find(*args) {|resource, args| ... } ⇒ Object
Finds the model object at a URL, given a model root
45 46 47 |
# File 'lib/compo/finders/url.rb', line 45 def self.find(*args, &block) new(*args).run(&block) end |
Instance Method Details
#run {|resource, args| ... } ⇒ Object
Attempts to find a child resource with the given partial URL
If the resource is found, it will be yielded to the attached block; otherwise, an exception will be raised.
63 64 65 66 67 68 69 70 |
# File 'lib/compo/finders/url.rb', line 63 def run # We're traversing down the URL by repeatedly splitting it into its # head (part before the next /) and tail (part after). While we still # have a tail, then the URL still needs walking down. reset descend until hit_end_of_url? yield @resource end |