0
@@ -5,53 +5,55 @@ module Waves
0
METHODS = %w( get put post delete ).map( &:intern )
0
RULES = %w( before action after always ).map( &:intern )
0
- def method_missing( name, *args, &block )
0
- mappings[ name ].push( map( *args, &block ) )
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 handle( exception )
0
def with( options, &block )
0
@options = options; yield if block_given? ; @options = nil
0
def path( name, options = {}, &block )
0
- map
pings[ :action ] = map( options.merge!( :name => name, :target => :path ), &block )
0
+ map
( options.merge!( :name => name, :target => :path ), &block )
0
def url( name, options = {}, &block )
0
- map
pings[ :action ] = map( options.merge!( :name => name, :target => :url ), &block )
0
+ map
( options.merge!( :name => name, :target => :url ), &block )
0
- def map( *args, &block )
0
- options = ( @options || {} ).merge( normalize( *args ) )
0
+ def map( options, &block )
0
+ options = ( @options || {} ).merge( options )
0
options[ :target ] ||= :path
0
options[ :method ] = method = METHODS.find { |method| options[ method ] }
0
options[ :pattern ] = options[ method ]
0
-
Action.new( options, &block )
0
+
mappings[ :action ].push( Action.new( options, &block ) )
0
- results = {} ; RULES.each do | rule |
0
- results[ rule ] = mappings[ rule ].select do | action |
0
- ( params = action.call?( request ) ) and Action::Binding.new( action, params )
0
+ returning Hash.new { |h,k| h[k] = [] } do | results |
0
+ RULES.each do | rule |
0
+ mappings[ rule ].each { | action | binding = action.bind( request ) and results[ rule ].push( binding ) }
0
- include Functor::Method
0
- functor( :normalize, Symbol, Hash ) { | name, options | options.merge!( :name => name ) }
0
- functor( :normalize, String, Hash ) { | pattern, options | options.merge!( :pattern => pattern ) }
0
- functor( :normalize, Regexp, Hash ) { | regexp, options | options.merge!( :pattern => regexp ) }
0
- functor( :normalize, Exception ) { | exception | { :exception => exception } }
0
- functor( :normalize, Hash ) { | options | options }
0
\ No newline at end of file
Comments
No one has commented yet.