0
@@ -45,48 +45,50 @@ module Waves
0
include Functor::Method
0
METHODS = %w( get put post delete ).map( &:intern )
0
- RULES = %w( before
response after always handle ).map( &:intern )
0
+ RULES = %w( before
after always ).map( &:intern )
0
def mappings ; @mappings ||= Hash.new { |h,k| h[k] = [] } ; end
0
def clear ; @mappings = Hash.new { |h,k| h[k] = [] } ; end
0
- def method_missing( name, *args, &block )
0
- return super unless RULES.include? name
0
- args << block if block_given?
0
- mappings[ name ] << map( *args )
0
def on( options, &block )
0
args = [options, block].compact
0
- mappings[ :response ] << map( *args )
0
+ mappings[ @type ] << map( *args )
0
+ @type = :before; yield if block; @type = nil
0
+ @type = :after; yield if block; @type = nil
0
+ @type = :always; yield if block; @type = nil
0
+ def handle(exception, options={}, &block)
0
+ args = [ exception, options, block].compact
0
+ mappings[ :handle ] << map( *args )
0
def with( options, &block )
0
@options = options; yield if block_given? ; @options = nil
0
- # primary input like: response( :klump, :get => [ "foo" ] ) { bar }
0
- functor( :map, Symbol, Hash, Proc ) do | name, options, block |
0
- options[:as] = name ; options[:block] = block ; map( options )
0
- end # no longer needed?
0
# primary input like: on( :get => [ "foo" ], :as => :klump ) { bar }
0
functor( :map, Hash, Proc ) do | options, block |
0
options[:block] = block; map( options )
0
- # primary input like response( :klump, :get => [ "foo" ] ); missing a block
0
- functor( :map, Symbol, Hash ) { | name, options | options[:as] = name ; map( options ) } # no longer needed?
0
# secondary input where &block has already been slurped into the options hash
0
functor( :map, Hash ) do | options |
0
raise ArgumentError, "A mapping must have a block or an :as param" if !options[:as] && !options[:block]
0
options = ( @options || {} ).merge( options )
0
options[ :method ] = method = METHODS.find { |method| options[ method ] }
0
- options[ :path ] = options[ method
] if method0
+ options[ :path ] = options[ method
|| :any ] 0
@@ -106,11 +108,11 @@ module Waves
0
results = Hash.new { |h,k| h[k] = [] }
0
-
RULES.each do | rule |
0
+
(RULES + [ :handle, :main] ).each do | rule |
0
mappings[ rule ].each { | action | ( binding = action.bind( request ) ) and results[ rule ].push( binding ) }
Comments
No one has commented yet.