Module: Kaffe::Actions::ClassMethods

Defined in:
lib/kaffe/actions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



5
6
7
# File 'lib/kaffe/actions.rb', line 5

def actions
  @actions
end

Instance Method Details

#action(method, path, &block) ⇒ Object



12
13
14
15
16
17
# 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) ⇒ Object



8
# File 'lib/kaffe/actions.rb', line 8

def call(env); instance.call(env) end

#compile!(path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Object



9
# File 'lib/kaffe/actions.rb', line 9

def get(path, &block); action('GET', path, &block) end

#post(path, &block) ⇒ Object



10
# File 'lib/kaffe/actions.rb', line 10

def post(path, &block); action('POST', path, &block) end