public
Rubygem
Description: Resource-oriented open source Ruby framework for Web apps.
Homepage: http://rubywaves.com/
Clone URL: git://github.com/dyoder/waves.git
dyoder (author)
Tue Jul 22 20:27:25 -0700 2008
commit  8b347b72928276bce6a0ee84c972fedbcc0ad7dc
tree    54fda62183d2ef375e5f8cc18e38018814b8f0c2
parent  a8c522c7170cc0b1c33e4d69c0cfb5c4b1047ea9
waves / lib / mapping / constraints.rb
100644 28 lines (19 sloc) 0.616 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Waves
 
  module Mapping
    
    class Constraints
      
      METHODS = %w( domain scheme method accept ).map( &:intern )
      
      def initialize( options )
        METHODS.each do | method |
          instance_variable_set( "@#{method}", options[ method ] ) if options[ method ]
        end
      end
      
      def satisfy?( request )
        METHODS.all? do | method |
          wanted = instance_variable_get( "@#{method}")
          got = request.send( method ) if wanted
          wanted.is_a?( Proc ) ? wanted.call( got ) : wanted === got
        end
      end
            
    end
 
  end
 
end