Module: Roda::RodaPlugins::HashPaths::ClassMethods

Defined in:
lib/roda/plugins/hash_paths.rb

Instance Method Summary collapse

Instance Method Details

#freezeObject

Freeze the hash_paths metadata when freezing the app.



84
85
86
87
# File 'lib/roda/plugins/hash_paths.rb', line 84

def freeze
  opts[:hash_paths].freeze.each_value(&:freeze)
  super
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.



104
105
106
107
108
109
110
111
# File 'lib/roda/plugins/hash_paths.rb', line 104

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.delete(path)
    remove_method(meth)
  end
end

#inherited(subclass) ⇒ Object

Duplicate hash_paths metadata in subclass.



90
91
92
93
94
95
96
97
# File 'lib/roda/plugins/hash_paths.rb', line 90

def inherited(subclass)
  super

  h = subclass.opts[:hash_paths]
  opts[:hash_paths].each do |namespace, routes|
    h[namespace] = routes.dup
  end
end