class Roda::RodaPlugins::HashRoutes::DSL
Internal class handling the internals of the hash_routes
class method blocks.
Public Class Methods
Source
# File lib/roda/plugins/hash_routes.rb, line 183 def initialize(roda, namespace) @roda = roda @namespace = namespace end
Public Instance Methods
Source
# File lib/roda/plugins/hash_routes.rb, line 191 def dispatch_from(namespace='', branch, &block) ns = @namespace if block meth_hash = @roda.opts[:hash_routes_methods] key = [:dispatch_from, namespace, branch].freeze meth = meth_hash[key] = @roda.define_roda_method(meth_hash[key] || "hash_routes_dispatch_from_#{namespace}_#{branch}", 1, &block) @roda.hash_branch(namespace, branch) do |r| send(meth, r) r.hash_routes(ns) end else @roda.hash_branch(namespace, branch) do |r| r.hash_routes(ns) end end end
Setup the given branch in the given namespace to dispatch to routes in this namespace. If a block is given, call the block with the request before dispatching to routes in this namespace.
Source
# File lib/roda/plugins/hash_routes.rb, line 216 def is(path, &block) path = path == true ? "" : "/#{path}" @roda.hash_path(@namespace, path, &block) end
Use the segment to setup a path in the current namespace. If path is given as a string, it is prefixed with a slash. If path is true
, the empty string is used as the path.
Source
# File lib/roda/plugins/hash_routes.rb, line 209 def on(segment, &block) @roda.hash_branch(@namespace, segment, &block) end
Use the segment to setup a branch in the current namespace.
Source
# File lib/roda/plugins/hash_routes.rb, line 226 def view(path, template) path = path == true ? "" : "/#{path}" @roda.hash_path(@namespace, path) do |r| r.get do view(template) end end end
Use the segment to setup a path in the current namespace that will render the view with the given name if the GET method is used, and will return a 404 if another request method is used. If path is given as a string, it is prefixed with a slash. If path is true
, the empty string is used as the path.
Source
# File lib/roda/plugins/hash_routes.rb, line 238 def views(templates) templates.each do |template| view(template, template) end end
For each template in the array of templates, setup a path in the current namespace for the template using the same name as the template.
Private Instance Methods
Source
# File lib/roda/plugins/hash_routes.rb, line 254 def verb(verb, path, &block) path = path == true ? "" : "/#{path}" meth_hash = @roda.opts[:hash_routes_methods] key = [@namespace, path].freeze meth = meth_hash[key] = @roda.define_roda_method(meth_hash[key] || "hash_routes_#{@namespace}_#{path}", 0, &block) @roda.hash_path(@namespace, path) do |r| r.send(verb) do send(meth) end end end
Setup a path in the current namespace for the given request method verb. Returns 404 for requests for the path with a different request method.