lib/tynn/matchers.rb in tynn-1.0.0.rc1 vs lib/tynn/matchers.rb in tynn-1.0.0.rc2

- old
+ new

@@ -1,58 +1,60 @@ -# Adds extra matchers to Tynn. -# -# ``` -# require "tynn" -# require "tynn/matchers" -# -# Tynn.helpers(Tynn::Matchers) -# ``` -# -module Tynn::Matchers - # A catch-all matcher. +class Tynn + # Adds extra matchers to Tynn. # # ``` - # Tynn.define do - # authenticated? do - # # ... - # end + # require "tynn" + # require "tynn/matchers" # - # default do # on true - # # ... - # end - # end + # Tynn.helpers(Tynn::Matchers) # ``` # - # :call-seq: default(&block) - # - def default - yield + module Matchers + # A catch-all matcher. + # + # ``` + # Tynn.define do + # authenticated? do + # # ... + # end + # + # default do # on true + # # ... + # end + # end + # ``` + # + # :call-seq: default(&block) + # + def default + yield - halt(res.finish) - end + halt(res.finish) + end - # Match if the given `key` is present in `req.params`. - # - # ``` - # Tynn.define do - # param(:user) do |params| - # user = User.create(params) - # - # # ... - # end - # - # default do - # res.write("missing param") - # end - # end - # ``` - # - # :call-seq: param(key, &block) - # - def param(key) - if (v = req[key]) && !v.empty? - yield(v) + # Match if the given `key` is present in `req.params`. + # + # ``` + # Tynn.define do + # param(:user) do |params| + # user = User.create(params) + # + # # ... + # end + # + # default do + # res.write("missing user param") + # end + # end + # ``` + # + # :call-seq: param(key, &block) + # + def param(key) + if (v = req[key]) && !v.empty? + yield(v) - halt(res.finish) + halt(res.finish) + end end end end