module Kaffe::Actions::ClassMethods
Attributes
actions[RW]
Public Instance Methods
action(method, path, &block)
click to toggle source
# File lib/kaffe/actions.rb, line 12 def action(method, path, &block) id = :"#{method} #{path}" define_method(id, &block) expr, keys = compile!(path) actions[method] << [expr, keys, id] end
call(env)
click to toggle source
# File lib/kaffe/actions.rb, line 8 def call(env); instance.call(env) end
compile!(path)
click to toggle source
# File lib/kaffe/actions.rb, line 19 def compile!(path) keys = [] if path.is_a? Regexp keys = 'splat' pattern = path elsif path.is_a? String pattern =path.gsub(/(:\w+)/) do |match| keys << $1[1..-1] "([^/?&#]+)" end end return [/^#{pattern}$/, keys] end
get(path, &block)
click to toggle source
# File lib/kaffe/actions.rb, line 9 def get(path, &block); action('GET', path, &block) end
post(path, &block)
click to toggle source
# File lib/kaffe/actions.rb, line 10 def post(path, &block); action('POST', path, &block) end