Module: Sinatra::Bind::ClassMethods

Defined in:
lib/sinatra/bind.rb

Constant Summary collapse

FILTER_NAMES =
['BEFORE', 'AFTER'].freeze

Instance Method Summary collapse

Instance Method Details

#on(path, options = {}) ⇒ Object

Defines a route without block smoothly

Parameters:

  • path (String)
  • [String, (Hash)

    a customizable set of options



42
43
44
45
46
47
48
49
50
# File 'lib/sinatra/bind.rb', line 42

def on(path, options = {})
  verb = (options.delete(:type) || 'GET').to_s.upcase
  return bound_filter(verb, path, options) if FILTER_NAMES.include?(verb)
  method_name = options.delete(:to)
  process_bound_route(verb, path, method_name) do
    method = instance_method(method_name)
    bound_route(verb, path, options.merge(method_name: "#{verb} #{method_name}"), method)
  end
end