Module: Tynn::Matchers::InstanceMethods

Defined in:
lib/tynn/matchers.rb

Instance Method Summary collapse

Instance Method Details

#defaultObject

Public: A catch-all matcher. Always executes the given block.

Examples

Tynn.define do
  authenticated? do
    # ...
  end

  default do # on true
    # ...
  end
end


27
28
29
30
31
# File 'lib/tynn/matchers.rb', line 27

def default
  yield

  halt(res.finish)
end

#param(key) ⇒ Object

Public: Executes the given block if key is present in req.params.

key - Any object that responds to to_s.

Examples

Tynn.define do
  param(:user) do |params|
    user = User.create(params)

    # ...
  end

  default do
    res.write("missing [user] param")
  end
end


51
52
53
54
55
56
57
# File 'lib/tynn/matchers.rb', line 51

def param(key)
  if (v = req[key]) && !v.empty?
    yield(v)

    halt(res.finish)
  end
end