11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/airship/attachment/sinatra.rb', line 11
def compile!(verb, path, block, options = {})
options = options.dup
if method_name = options.delete(:to)
block = unbound_method = instance_method(method_name) rescue undefined_method(method_name)
else
method_name = "#{verb} #{path}"
unbound_method = generate_method(method_name, &block)
end
options.each_pair { |option, args| send(option, *args) }
pattern, keys = compile path
conditions, @conditions = @conditions, []
wrapper = block.arity != 0 ?
proc { |a,p| unbound_method.bind(a).call(*p) } :
proc { |a,p| unbound_method.bind(a).call }
wrapper.instance_variable_set(:@route_name, method_name)
[ pattern, keys, conditions, wrapper ]
end
|