Internal class handling the internals of the hash_routes
class method blocks.
Public Class methods
# File lib/roda/plugins/hash_routes.rb 183 def initialize(roda, namespace) 184 @roda = roda 185 @namespace = namespace 186 end
Public Instance methods
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.
# File lib/roda/plugins/hash_routes.rb 191 def dispatch_from(namespace='', branch, &block) 192 ns = @namespace 193 if block 194 meth_hash = @roda.opts[:hash_routes_methods] 195 key = [:dispatch_from, namespace, branch].freeze 196 meth = meth_hash[key] = @roda.define_roda_method(meth_hash[key] || "hash_routes_dispatch_from_#{namespace}_#{branch}", 1, &block) 197 @roda.hash_branch(namespace, branch) do |r| 198 send(meth, r) 199 r.hash_routes(ns) 200 end 201 else 202 @roda.hash_branch(namespace, branch) do |r| 203 r.hash_routes(ns) 204 end 205 end 206 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.
# File lib/roda/plugins/hash_routes.rb 216 def is(path, &block) 217 path = path == true ? "" : "/#{path}" 218 @roda.hash_path(@namespace, path, &block) 219 end
Use the segment to setup a branch in the current namespace.
# File lib/roda/plugins/hash_routes.rb 209 def on(segment, &block) 210 @roda.hash_branch(@namespace, segment, &block) 211 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.
# File lib/roda/plugins/hash_routes.rb 226 def view(path, template) 227 path = path == true ? "" : "/#{path}" 228 @roda.hash_path(@namespace, path) do |r| 229 r.get do 230 view(template) 231 end 232 end 233 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.
# File lib/roda/plugins/hash_routes.rb 238 def views(templates) 239 templates.each do |template| 240 view(template, template) 241 end 242 end