lib/roda/plugins/endpoints.rb in roda-endpoints-0.3.2 vs lib/roda/plugins/endpoints.rb in roda-endpoints-0.3.3
- old
+ new
@@ -95,15 +95,17 @@
# end
def collection(name,
item: { on: :id },
type: Roda::Endpoints::Endpoint::Collection,
on: name.to_s,
+ parent: root_endpoint,
**kwargs)
endpoint name: name,
item: item,
type: type,
on: on,
+ parent: parent,
**kwargs do |endpoint|
yield endpoint if block_given?
end
end
@@ -177,10 +179,11 @@
type:,
container: roda_class.opts[:endpoints][:container],
parent: current_endpoint,
on: name,
**kwargs)
+ parent ||= root_endpoint
on on do |*captures|
with_current_endpoint parent.child(
name: name,
type: type,
container: container,
@@ -224,14 +227,18 @@
endpoints.last
end
# @return [<Endpoint>]
def endpoints
- @endpoints ||= [Roda::Endpoints::Endpoint.new(
+ @endpoints ||= [root_endpoint]
+ end
+
+ def root_endpoint
+ @root_endpoint ||= Roda::Endpoints::Endpoint.new(
name: :root,
ns: nil,
container: roda_class.opts[:endpoints][:container]
- )]
+ )
end
def with_current_endpoint(endpoint)
endpoints.push endpoint
yield endpoint