Module: Roda::RodaPlugins::HashBranches::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#freezeObject

Freeze the hash_branches metadata when freezing the app.



92
93
94
95
# File 'lib/roda/plugins/hash_branches.rb', line 92

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



109
110
111
112
113
114
115
116
117
# File 'lib/roda/plugins/hash_branches.rb', line 109

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

#inherited(subclass) ⇒ Object

Duplicate hash_branches metadata in subclass.



98
99
100
101
102
103
104
105
# File 'lib/roda/plugins/hash_branches.rb', line 98

def inherited(subclass)
  super

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