joshbuddy-usher 0.0.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/History.txt +3 -0
- data/Manifest.txt +35 -0
- data/README.rdoc +63 -0
- data/Rakefile +27 -0
- data/lib/compat.rb +1 -0
- data/lib/usher.rb +135 -0
- data/lib/usher/exceptions.rb +4 -0
- data/lib/usher/grapher.rb +44 -0
- data/lib/usher/interface.rb +22 -0
- data/lib/usher/interface/merb_interface.rb +63 -0
- data/lib/usher/interface/rack_interface.rb +31 -0
- data/lib/usher/interface/rack_interface/mapper.rb +0 -0
- data/lib/usher/interface/rack_interface/route.rb +9 -0
- data/lib/usher/interface/rails2_interface.rb +133 -0
- data/lib/usher/interface/rails2_interface/mapper.rb +44 -0
- data/lib/usher/node.rb +149 -0
- data/lib/usher/node/lookup.rb +78 -0
- data/lib/usher/route.rb +33 -0
- data/lib/usher/route/http.rb +21 -0
- data/lib/usher/route/path.rb +20 -0
- data/lib/usher/route/separator.rb +21 -0
- data/lib/usher/route/splitter.rb +93 -0
- data/lib/usher/route/variable.rb +22 -0
- data/rails/init.rb +4 -0
- data/spec/generate_spec.rb +61 -0
- data/spec/node/lookup_spec.rb +53 -0
- data/spec/path_spec.rb +42 -0
- data/spec/rack/dispatch_spec.rb +36 -0
- data/spec/rails/generate_spec.rb +28 -0
- data/spec/rails/path_spec.rb +16 -0
- data/spec/rails/recognize_spec.rb +79 -0
- data/spec/recognize_spec.rb +66 -0
- data/spec/spec.opts +7 -0
- data/spec/split_spec.rb +37 -0
- data/usher.gemspec +32 -0
- metadata +98 -0
| @@ -0,0 +1,66 @@ | |
| 1 | 
            +
            require 'lib/usher'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            route_set = Usher.new
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            def build_request(opts)
         | 
| 6 | 
            +
              request = mock "Request"
         | 
| 7 | 
            +
              opts.each do |k,v|
         | 
| 8 | 
            +
                request.should_receive(k).any_number_of_times.and_return(v)
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
              request
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            SampleController = Object.new
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            describe "Usher route recognition" do
         | 
| 16 | 
            +
              
         | 
| 17 | 
            +
              before(:each) do
         | 
| 18 | 
            +
                route_set.reset!
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
              it "should recognize a specific domain name" do
         | 
| 22 | 
            +
                target_route = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http'})
         | 
| 23 | 
            +
                route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https'})
         | 
| 24 | 
            +
                target_route.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http'})).first).should == true
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
              
         | 
| 27 | 
            +
              it "should recognize a regex domain name" do
         | 
| 28 | 
            +
                target_route = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:domain => /^admin.*$/})
         | 
| 29 | 
            +
                route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:domain => 'www.host.com'})
         | 
| 30 | 
            +
                target_route.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/sample', :domain => 'admin.host.com'})).first).should == true
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
              
         | 
| 33 | 
            +
              it "should recognize a specific route when several http-style restrictions are used" do
         | 
| 34 | 
            +
                target_route_http_admin = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http', :domain => 'admin.spec.com'})
         | 
| 35 | 
            +
                target_route_http_www = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http', :domain => 'www.spec.com'})
         | 
| 36 | 
            +
                target_route_https_msie = route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https', :user_agent => 'MSIE 6.0'})
         | 
| 37 | 
            +
                target_route_https_admin = route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https', :domain => 'admin.spec.com'})
         | 
| 38 | 
            +
                target_route_http_admin.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http', :domain => 'admin.spec.com', :user_agent => nil})).first).should == true
         | 
| 39 | 
            +
                target_route_http_www.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http', :domain => 'www.spec.com', :user_agent => nil})).first).should == true
         | 
| 40 | 
            +
                target_route_https_msie.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'https', :domain => 'admin.spec.com', :user_agent => 'MSIE 6.0'})).first).should == true
         | 
| 41 | 
            +
                target_route_https_admin.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'https', :domain => 'admin.spec.com', :user_agent => nil})).first).should == true
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
              
         | 
| 44 | 
            +
              it "should correctly fix that tree if conditionals are used later" do
         | 
| 45 | 
            +
                noop_route = route_set.add_route('noop', :controller => 'products', :action => 'noop')
         | 
| 46 | 
            +
                product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:method => 'get'})
         | 
| 47 | 
            +
                noop_route.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/noop', :domain => 'admin.host.com'})).first).should == true
         | 
| 48 | 
            +
                product_show_route.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com'})).first).should == true
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
              
         | 
| 51 | 
            +
              it "should use a transformer (proc) on incoming variables" do
         | 
| 52 | 
            +
                route_set.add_route('/:controller/:action/:id', :transformers => {:id => proc{|v| v.to_i}})
         | 
| 53 | 
            +
                route_set.recognize(build_request({:method => 'get', :path => '/products/show/123asd', :domain => 'admin.host.com'})).last.rassoc(123).first.should == :id
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
              
         | 
| 56 | 
            +
              it "should use a transformer (symbol) on incoming variables" do
         | 
| 57 | 
            +
                route_set.add_route('/:controller/:action/:id', :transformers => {:id => :to_i})
         | 
| 58 | 
            +
                route_set.recognize(build_request({:method => 'get', :path => '/products/show/123asd', :domain => 'admin.host.com'})).last.rassoc(123).first.should == :id
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
              
         | 
| 61 | 
            +
              it "should should raise if malformed variables are used" do
         | 
| 62 | 
            +
                route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:method => 'get'})
         | 
| 63 | 
            +
                proc {route_set.recognize(build_request({:method => 'get', :path => '/products/show/qweasd', :domain => 'admin.host.com'}))}.should raise_error
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
              
         | 
| 66 | 
            +
            end
         | 
    
        data/spec/spec.opts
    ADDED
    
    
    
        data/spec/split_spec.rb
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            require 'lib/usher'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Slash = Usher::Route::Separator::Slash
         | 
| 4 | 
            +
            Dot = Usher::Route::Separator::Dot
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            describe "Usher route tokenizing" do
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              it "should split / delimited routes" do
         | 
| 10 | 
            +
                Usher::Route::Splitter.new('/test/this/split').paths.first.should == [Slash, 'test', Slash, 'this', Slash, 'split']
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
              
         | 
| 13 | 
            +
              it "should group optional parts with brackets" do
         | 
| 14 | 
            +
                Usher::Route::Splitter.new('/test/this(/split)').paths.should == [
         | 
| 15 | 
            +
                  [Slash, 'test', Slash, 'this'],
         | 
| 16 | 
            +
                  [Slash, 'test', Slash, 'this', Slash, 'split']
         | 
| 17 | 
            +
                ]
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              it "should group optional parts with brackets (for non overlapping groups)" do
         | 
| 21 | 
            +
                Usher::Route::Splitter.new('/test/this(/split)(/split2)').paths == [
         | 
| 22 | 
            +
                  [Slash, "test", Slash, "this"],
         | 
| 23 | 
            +
                  [Slash, "test", Slash, "this", Slash, "split"],
         | 
| 24 | 
            +
                  [Slash, "test", Slash, "this", Slash, "split2"],
         | 
| 25 | 
            +
                  [Slash, "test", Slash, "this", Slash, "split", Slash, "split2"]
         | 
| 26 | 
            +
                ]
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              it "should group nested-optional parts with brackets" do
         | 
| 30 | 
            +
                Usher::Route::Splitter.new('/test/this(/split(.:format))').paths == [
         | 
| 31 | 
            +
                  [Slash, "test", Slash, "this"],
         | 
| 32 | 
            +
                  [Slash, "test", Slash, "this", Slash, "split"],
         | 
| 33 | 
            +
                  [Slash, "test", Slash, "this", Slash, "split", Dot, Usher::Route::Variable.new(:':', :format)]
         | 
| 34 | 
            +
                ]
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
              
         | 
| 37 | 
            +
            end
         | 
    
        data/usher.gemspec
    ADDED
    
    | @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Gem::Specification.new do |s|
         | 
| 4 | 
            +
              s.name = %q{usher}
         | 
| 5 | 
            +
              s.version = "0.0.2"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 8 | 
            +
              s.authors = ["Joshua HullJoshua Hull"]
         | 
| 9 | 
            +
              s.date = %q{2009-03-01}
         | 
| 10 | 
            +
              s.email = %q{joshbuddy@gmail.comjoshbuddy@gmail.com}
         | 
| 11 | 
            +
              s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
         | 
| 12 | 
            +
              s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "lib/compat.rb", "lib/usher.rb", "lib/usher/exceptions.rb", "lib/usher/grapher.rb", "lib/usher/interface.rb", "lib/usher/interface/merb_interface.rb", "lib/usher/interface/rack_interface.rb", "lib/usher/interface/rack_interface/mapper.rb", "lib/usher/interface/rack_interface/route.rb", "lib/usher/interface/rails2_interface.rb", "lib/usher/interface/rails2_interface/mapper.rb", "lib/usher/node.rb", "lib/usher/node/lookup.rb", "lib/usher/route.rb", "lib/usher/route/http.rb", "lib/usher/route/path.rb", "lib/usher/route/separator.rb", "lib/usher/route/splitter.rb", "lib/usher/route/variable.rb", "rails/init.rb", "spec/generate_spec.rb", "spec/node/lookup_spec.rb", "spec/path_spec.rb", "spec/rack/dispatch_spec.rb", "spec/rails/generate_spec.rb", "spec/rails/path_spec.rb", "spec/rails/recognize_spec.rb", "spec/recognize_spec.rb", "spec/spec.opts", "spec/split_spec.rb", "usher.gemspec"]
         | 
| 13 | 
            +
              s.has_rdoc = true
         | 
| 14 | 
            +
              s.rdoc_options = ["--main", "README.rdoc"]
         | 
| 15 | 
            +
              s.require_paths = ["lib"]
         | 
| 16 | 
            +
              s.rubyforge_project = %q{usher}
         | 
| 17 | 
            +
              s.rubygems_version = %q{1.3.1}
         | 
| 18 | 
            +
              s.summary = %q{Tree-based router}
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              if s.respond_to? :specification_version then
         | 
| 21 | 
            +
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         | 
| 22 | 
            +
                s.specification_version = 2
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
         | 
| 25 | 
            +
                  s.add_development_dependency(%q<hoe>, [">= 1.8.3"])
         | 
| 26 | 
            +
                else
         | 
| 27 | 
            +
                  s.add_dependency(%q<hoe>, [">= 1.8.3"])
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              else
         | 
| 30 | 
            +
                s.add_dependency(%q<hoe>, [">= 1.8.3"])
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,98 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: joshbuddy-usher
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors: 
         | 
| 7 | 
            +
            - Joshua HullJoshua Hull
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            date: 2009-03-01 00:00:00 -08:00
         | 
| 13 | 
            +
            default_executable: 
         | 
| 14 | 
            +
            dependencies: 
         | 
| 15 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 16 | 
            +
              name: hoe
         | 
| 17 | 
            +
              type: :development
         | 
| 18 | 
            +
              version_requirement: 
         | 
| 19 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 20 | 
            +
                requirements: 
         | 
| 21 | 
            +
                - - ">="
         | 
| 22 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 23 | 
            +
                    version: 1.8.3
         | 
| 24 | 
            +
                version: 
         | 
| 25 | 
            +
            description: 
         | 
| 26 | 
            +
            email: joshbuddy@gmail.comjoshbuddy@gmail.com
         | 
| 27 | 
            +
            executables: []
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            extensions: []
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            extra_rdoc_files: 
         | 
| 32 | 
            +
            - History.txt
         | 
| 33 | 
            +
            - Manifest.txt
         | 
| 34 | 
            +
            files: 
         | 
| 35 | 
            +
            - History.txt
         | 
| 36 | 
            +
            - Manifest.txt
         | 
| 37 | 
            +
            - README.rdoc
         | 
| 38 | 
            +
            - Rakefile
         | 
| 39 | 
            +
            - lib/compat.rb
         | 
| 40 | 
            +
            - lib/usher.rb
         | 
| 41 | 
            +
            - lib/usher/exceptions.rb
         | 
| 42 | 
            +
            - lib/usher/grapher.rb
         | 
| 43 | 
            +
            - lib/usher/interface.rb
         | 
| 44 | 
            +
            - lib/usher/interface/merb_interface.rb
         | 
| 45 | 
            +
            - lib/usher/interface/rack_interface.rb
         | 
| 46 | 
            +
            - lib/usher/interface/rack_interface/mapper.rb
         | 
| 47 | 
            +
            - lib/usher/interface/rack_interface/route.rb
         | 
| 48 | 
            +
            - lib/usher/interface/rails2_interface.rb
         | 
| 49 | 
            +
            - lib/usher/interface/rails2_interface/mapper.rb
         | 
| 50 | 
            +
            - lib/usher/node.rb
         | 
| 51 | 
            +
            - lib/usher/node/lookup.rb
         | 
| 52 | 
            +
            - lib/usher/route.rb
         | 
| 53 | 
            +
            - lib/usher/route/http.rb
         | 
| 54 | 
            +
            - lib/usher/route/path.rb
         | 
| 55 | 
            +
            - lib/usher/route/separator.rb
         | 
| 56 | 
            +
            - lib/usher/route/splitter.rb
         | 
| 57 | 
            +
            - lib/usher/route/variable.rb
         | 
| 58 | 
            +
            - rails/init.rb
         | 
| 59 | 
            +
            - spec/generate_spec.rb
         | 
| 60 | 
            +
            - spec/node/lookup_spec.rb
         | 
| 61 | 
            +
            - spec/path_spec.rb
         | 
| 62 | 
            +
            - spec/rack/dispatch_spec.rb
         | 
| 63 | 
            +
            - spec/rails/generate_spec.rb
         | 
| 64 | 
            +
            - spec/rails/path_spec.rb
         | 
| 65 | 
            +
            - spec/rails/recognize_spec.rb
         | 
| 66 | 
            +
            - spec/recognize_spec.rb
         | 
| 67 | 
            +
            - spec/spec.opts
         | 
| 68 | 
            +
            - spec/split_spec.rb
         | 
| 69 | 
            +
            - usher.gemspec
         | 
| 70 | 
            +
            has_rdoc: true
         | 
| 71 | 
            +
            homepage: 
         | 
| 72 | 
            +
            post_install_message: 
         | 
| 73 | 
            +
            rdoc_options: 
         | 
| 74 | 
            +
            - --main
         | 
| 75 | 
            +
            - README.rdoc
         | 
| 76 | 
            +
            require_paths: 
         | 
| 77 | 
            +
            - lib
         | 
| 78 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 79 | 
            +
              requirements: 
         | 
| 80 | 
            +
              - - ">="
         | 
| 81 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 82 | 
            +
                  version: "0"
         | 
| 83 | 
            +
              version: 
         | 
| 84 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 85 | 
            +
              requirements: 
         | 
| 86 | 
            +
              - - ">="
         | 
| 87 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 88 | 
            +
                  version: "0"
         | 
| 89 | 
            +
              version: 
         | 
| 90 | 
            +
            requirements: []
         | 
| 91 | 
            +
             | 
| 92 | 
            +
            rubyforge_project: usher
         | 
| 93 | 
            +
            rubygems_version: 1.2.0
         | 
| 94 | 
            +
            signing_key: 
         | 
| 95 | 
            +
            specification_version: 2
         | 
| 96 | 
            +
            summary: Tree-based router
         | 
| 97 | 
            +
            test_files: []
         | 
| 98 | 
            +
             |