Module: Roda::RodaPlugins::HashRoutes::ClassMethods
- Defined in:
- lib/roda/plugins/hash_routes.rb
Instance Method Summary collapse
-
#freeze ⇒ Object
Freeze the hash_routes metadata when freezing the app.
-
#hash_branch(namespace = '', segment, &block) ⇒ Object
Add branch handler for the given namespace and segment.
-
#hash_path(namespace = '', path, &block) ⇒ Object
Add path handler for the given namespace and path.
-
#hash_routes(namespace = '', &block) ⇒ Object
Invoke the DSL for configuring hash routes, see DSL for methods inside the block.
-
#inherited(subclass) ⇒ Object
Duplicate hash_routes metadata in subclass.
Instance Method Details
#freeze ⇒ Object
Freeze the hash_routes metadata when freezing the app.
361 362 363 364 365 366 |
# File 'lib/roda/plugins/hash_routes.rb', line 361 def freeze opts[:hash_branches].freeze.each_value(&:freeze) opts[:hash_paths].freeze.each_value(&:freeze) opts[:hash_routes_methods].freeze super end |
#hash_branch(namespace = '', segment, &block) ⇒ Object
Add branch handler for the given namespace and segment. If called without a block, removes the existing branch handler if it exists.
399 400 401 402 403 404 405 406 407 408 |
# File 'lib/roda/plugins/hash_routes.rb', line 399 def hash_branch(namespace='', segment, &block) segment = "/#{segment}" routes = opts[:hash_branches][namespace] ||= {} if block routes[segment] = define_roda_method(routes[segment] || "hash_branch_#{namespace}_#{segment}", 1, &convert_route_block(block)) elsif meth = routes[segment] routes.delete(segment) remove_method(meth) end end |
#hash_path(namespace = '', path, &block) ⇒ Object
Add path handler for the given namespace and path. When the r.hash_paths method is called, checks the matching namespace for the full remaining path, and dispatch to that block if there is one. If called without a block, removes the existing path handler if it exists.
415 416 417 418 419 420 421 422 423 |
# File 'lib/roda/plugins/hash_routes.rb', line 415 def hash_path(namespace='', path, &block) routes = opts[:hash_paths][namespace] ||= {} if block routes[path] = define_roda_method(routes[path] || "hash_path_#{namespace}_#{path}", 1, &convert_route_block(block)) elsif meth = routes[path] routes.delete(path) remove_method(meth) end end |
#hash_routes(namespace = '', &block) ⇒ Object
Invoke the DSL for configuring hash routes, see DSL for methods inside the block. If the block accepts an argument, yield the DSL instance. If the block does not accept an argument, instance_exec the block in the context of the DSL instance.
384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/roda/plugins/hash_routes.rb', line 384 def hash_routes(namespace='', &block) dsl = DSL.new(self, namespace) if block if block.arity == 1 yield dsl else dsl.instance_exec(&block) end end dsl end |
#inherited(subclass) ⇒ Object
Duplicate hash_routes metadata in subclass.
369 370 371 372 373 374 375 376 377 378 |
# File 'lib/roda/plugins/hash_routes.rb', line 369 def inherited(subclass) super [:hash_branches, :hash_paths].each do |k| h = subclass.opts[k] opts[k].each do |namespace, routes| h[namespace] = routes.dup end end end |