http_router 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/http_router/route.rb +25 -7
- data/lib/http_router/version.rb +1 -1
- data/test/test_recognize.rb +4 -1
- data/test/test_variable.rb +4 -3
- metadata +4 -4
    
        data/lib/http_router/route.rb
    CHANGED
    
    | @@ -2,20 +2,26 @@ require 'strscan' | |
| 2 2 |  | 
| 3 3 | 
             
            class HttpRouter
         | 
| 4 4 | 
             
              class Route
         | 
| 5 | 
            -
                attr_reader :dest, :paths, :path, :matches_with, :original_path
         | 
| 5 | 
            +
                attr_reader :dest, :paths, :path, :matches_with, :original_path, :regex
         | 
| 6 6 | 
             
                attr_accessor :trailing_slash_ignore, :partially_match, :default_values
         | 
| 7 7 |  | 
| 8 8 | 
             
                def initialize(router, path)
         | 
| 9 9 | 
             
                  @router = router
         | 
| 10 | 
            -
                  path[0,0] = '/' unless path[0] == ?/
         | 
| 11 | 
            -
                  @path = path
         | 
| 12 | 
            -
                  @original_path = path.dup
         | 
| 13 | 
            -
                  @partially_match = extract_partial_match(path)
         | 
| 14 | 
            -
                  @trailing_slash_ignore = extract_trailing_slash(path)
         | 
| 15 10 | 
             
                  @matches_with = {}
         | 
| 16 11 | 
             
                  @arbitrary = []
         | 
| 17 12 | 
             
                  @conditions =  {}
         | 
| 18 13 | 
             
                  @default_values = {}
         | 
| 14 | 
            +
                  case path
         | 
| 15 | 
            +
                  when Regexp
         | 
| 16 | 
            +
                    @regex = path
         | 
| 17 | 
            +
                    path = '/*'
         | 
| 18 | 
            +
                    match_path(@regex)
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                  @path = path
         | 
| 21 | 
            +
                  @original_path = path.dup
         | 
| 22 | 
            +
                  path[0,0] = '/' unless path[0] == ?/
         | 
| 23 | 
            +
                  @partially_match = extract_partial_match(path)
         | 
| 24 | 
            +
                  @trailing_slash_ignore = extract_trailing_slash(path)
         | 
| 19 25 | 
             
                end
         | 
| 20 26 |  | 
| 21 27 | 
             
                def method_missing(method, *args, &block)
         | 
| @@ -26,6 +32,10 @@ class HttpRouter | |
| 26 32 | 
             
                  end
         | 
| 27 33 | 
             
                end
         | 
| 28 34 |  | 
| 35 | 
            +
                def regex?
         | 
| 36 | 
            +
                  !@regex.nil?
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 29 39 | 
             
                def to_s
         | 
| 30 40 | 
             
                  "#{@original_path} conditions: #{@conditions.inspect} default_values: #{@default_values.inspect} name: #{named.inspect}"
         | 
| 31 41 | 
             
                end
         | 
| @@ -174,7 +184,15 @@ class HttpRouter | |
| 174 184 |  | 
| 175 185 | 
             
                # Convenient regexp matching on an entire path. Returns +self+
         | 
| 176 186 | 
             
                def match_path(matcher)
         | 
| 177 | 
            -
                  arbitrary{|env, params, dest| | 
| 187 | 
            +
                  arbitrary{|env, params, dest|
         | 
| 188 | 
            +
                    match = matcher.match(env.path_info)
         | 
| 189 | 
            +
                    if !match.nil? and match.begin(0) == 0 and match[0].size == env.path_info.size
         | 
| 190 | 
            +
                      env['router.regex_match'] = match
         | 
| 191 | 
            +
                      true
         | 
| 192 | 
            +
                    else
         | 
| 193 | 
            +
                      false
         | 
| 194 | 
            +
                    end
         | 
| 195 | 
            +
                  }
         | 
| 178 196 | 
             
                end
         | 
| 179 197 |  | 
| 180 198 | 
             
                # Adds an arbitrary proc matcher to a Route. Receives either a block, or a proc. The proc will receive a Rack::Request object, a Hash of the params, and the destination for this route. The proc must return true if the Route is matched. Returns +self+.
         | 
    
        data/lib/http_router/version.rb
    CHANGED
    
    
    
        data/test/test_recognize.rb
    CHANGED
    
    | @@ -1,6 +1,9 @@ | |
| 1 1 | 
             
            class TestRecognition < MiniTest::Unit::TestCase
         | 
| 2 | 
            -
              def  | 
| 2 | 
            +
              def test_empty
         | 
| 3 3 | 
             
                assert_route router.add(''),              '/'
         | 
| 4 | 
            +
              end
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def test_simple
         | 
| 4 7 | 
             
                assert_route router.add('/'),             '/'
         | 
| 5 8 | 
             
                assert_route router.add('/test'),         '/test'
         | 
| 6 9 | 
             
                assert_route router.add('/test/one'),     '/test/one'
         | 
    
        data/test/test_variable.rb
    CHANGED
    
    | @@ -50,9 +50,10 @@ class TestVariable < MiniTest::Unit::TestCase | |
| 50 50 | 
             
              end
         | 
| 51 51 |  | 
| 52 52 | 
             
              def test_match_path
         | 
| 53 | 
            -
                r = router { add( | 
| 54 | 
            -
                 | 
| 55 | 
            -
                assert_route r, '/ | 
| 53 | 
            +
                r = router { add(%r{/(test123|\d+)}) }
         | 
| 54 | 
            +
                assert_equal true, r.regex?
         | 
| 55 | 
            +
                assert_route r, '/test123'
         | 
| 56 | 
            +
                assert_route r, '/123'
         | 
| 56 57 | 
             
                assert_route nil, '/test123andmore'
         | 
| 57 58 | 
             
                assert_route nil, '/lesstest123'
         | 
| 58 59 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: http_router
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 15
         | 
| 5 5 | 
             
              prerelease: false
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 5
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.5. | 
| 9 | 
            +
              - 2
         | 
| 10 | 
            +
              version: 0.5.2
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Joshua Hull
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2011-01- | 
| 18 | 
            +
            date: 2011-01-20 00:00:00 -08:00
         | 
| 19 19 | 
             
            default_executable: 
         | 
| 20 20 | 
             
            dependencies: 
         | 
| 21 21 | 
             
            - !ruby/object:Gem::Dependency 
         |