0
@@ -2,50 +2,44 @@ module Waves
0
+ include Functor::Method
0
METHODS = %w( get put post delete ).map( &:intern )
0
- RULES = %w( before action after always
).map( &:intern )
0
+ RULES = %w( before action after always
, handle ).map( &:intern )
0
@mappings ||= Hash.new { |h,k| h[k] = [] }
0
- def before( options, &block )
0
- def wrap( name, *args, &block )
0
- before( name, *args, &block ) ; after( name, *args, &block )
0
- def after( options, &block )
0
- def always( options, &block )
0
+ def method_missing( name, *args, &block )
0
+ return super unless RULES.include? name
0
+ map( name, args, &block )
0
- def handle( exception )
0
def with( options, &block )
0
@options = options; yield if block_given? ; @options = nil
0
- def path( name, options = {}, &block )
0
- map( options.merge!( :name => name, :target => :path ), &block )
0
+ functor( :map, String, Array, Proc ) { | rule, args, block | map( *( args << block ) ) }
0
+ functor( :map, String, Array ) { | rule, args | mappings[ rule ] << map( *args ) }
0
+ functor( :map, String, Hash, Proc ) do | name, options, block |
0
+ options[:name] = name ; options[:block] = block ; map( options )
0
- def url( name, options = {}, &block )
0
- map( options.merge!( :name => name, :target => :url ), &block )
0
- def map( options, &block )
0
+ functor( :map, String, Hash ) { | name, options | options[:name] = name ; map( options ) }
0
+ functor( :map, Hash ) do | options |
0
options = ( @options || {} ).merge( options )
0
- options[ :target ] ||= :path
0
options[ :method ] = method = METHODS.find { |method| options[ method ] }
0
options[ :pattern ] = options[ method ]
0
-
mappings[ :action ].push( Action.new( options, &block ) )
0
+ functor( :map, Exception, String, Hash, Proc ) do | e, name, options, block |
0
+ options[:name] = name ; map( e, options, block )
0
+ functor( :map, Exception, Hash, Proc ) do | e, options, block |
0
+ options[:block] = block ; map( e, options )
0
+ functor( :map, Exception, Hash ) { | options, block | Handler.new( e, options ) }
0
returning Hash.new { |h,k| h[k] = [] } do | results |
0
@@ -53,7 +47,12 @@ module Waves
0
+ def normalize( options )
0
\ No newline at end of file
Comments
No one has commented yet.