sinatra-route-mapper 0.0.1

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.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --profile
3
+ --order random
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '1.9.3'
4
+
5
+ # Specify your gem's dependencies in auth-map.gemspec
6
+ gemspec
7
+
8
+ gem 'rspec', '~> 2.11.0'
9
+ gem 'rack-test', '~> 0.6.1', :require => 'rack/test'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yuriy Kharchenko
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Sinatra::RouteMapper
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sinatra-route-mapper'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sinatra-route-mapper
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ require 'rack/request'
2
+ require 'sinatra'
3
+
4
+ module Sinatra
5
+ class RouteMapper < Sinatra::Base
6
+
7
+ VERSION = '0.0.1'
8
+
9
+ disable :show_exceptions
10
+ enable :raise_errors
11
+
12
+ def map=(route_map)
13
+ route_map.each do |url, verb_list|
14
+ [verb_list].flatten.each do |verb|
15
+ self.class.send(verb, url) do
16
+ @on_match.call(env) if @on_match
17
+ forward
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def on_match(&block)
24
+ @on_match = block
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sinatra/route_mapper'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sinatra-route-mapper"
8
+ gem.version = Sinatra::RouteMapper::VERSION
9
+ gem.authors = ["Yuriy Kharchenko"]
10
+ gem.email = ["yuri.kharchenko@gmail.com"]
11
+ gem.description = %q{Sinatra middleware to assign a callback on a certain route set}
12
+ gem.summary = %q{Sinatra middleware}
13
+ gem.homepage = "https://github.com/letmein/sinatra-route-mapper"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "rack"
21
+ gem.add_dependency "sinatra"
22
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sinatra::RouteMapper do
4
+
5
+ let(:app) do
6
+ Class.new(Sinatra::Base) do
7
+
8
+ disable :show_exceptions
9
+ enable :raise_errors
10
+
11
+ use Sinatra::RouteMapper do |config|
12
+ config.map = {
13
+ '/foo' => :get,
14
+ '/bar' => [:get, :post]
15
+ }
16
+ config.on_match do |env|
17
+ env['request_matched'] = true
18
+ end
19
+ end
20
+
21
+ get('/foo') { 'get foo' }
22
+ get('/bar') { 'get bar' }
23
+ post('/bar') { 'post bar' }
24
+ get('/baz') { 'get baz' }
25
+ end
26
+ end
27
+
28
+ context "when an url is matched by a single HTTP verb" do
29
+ before do
30
+ get '/foo'
31
+ end
32
+
33
+ it "should forward the request to the main app" do
34
+ last_response.body.should eq 'get foo'
35
+ end
36
+
37
+ it "should run the callback" do
38
+ last_request.env['request_matched'].should be_true
39
+ end
40
+ end
41
+
42
+ context "when an url is matched by more than one HTTP verb" do
43
+ context "and one of the verbs was requested" do
44
+ before do
45
+ get '/bar'
46
+ end
47
+
48
+ it "should run the callback" do
49
+ last_request.env['request_matched'].should be_true
50
+ end
51
+
52
+ it "should forward the request to the main app" do
53
+ last_response.body.should eq 'get bar'
54
+ end
55
+ end
56
+
57
+ context "and another verb from the list was requested" do
58
+ before do
59
+ post '/bar'
60
+ end
61
+
62
+ it "should run the callback" do
63
+ last_request.env['request_matched'].should be_true
64
+ end
65
+
66
+ it "should forward the request to the main app" do
67
+ last_response.body.should eq 'post bar'
68
+ end
69
+ end
70
+ end
71
+
72
+ context "when an url has no match" do
73
+ before do
74
+ get '/baz'
75
+ end
76
+
77
+ it "should not run the callback" do
78
+ last_request.env['request_matched'].should be_nil
79
+ end
80
+
81
+ it "should forward the request to the main app" do
82
+ last_response.body.should eq 'get baz'
83
+ end
84
+ end
85
+
86
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rack/test'
4
+ require 'sinatra/route_mapper'
5
+
6
+ RSpec.configure do |conf|
7
+
8
+ conf.include Rack::Test::Methods
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-route-mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yuriy Kharchenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: &13410160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *13410160
25
+ - !ruby/object:Gem::Dependency
26
+ name: sinatra
27
+ requirement: &13409740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *13409740
36
+ description: Sinatra middleware to assign a callback on a certain route set
37
+ email:
38
+ - yuri.kharchenko@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .rspec
45
+ - Gemfile
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - lib/sinatra/route_mapper.rb
50
+ - sinatra-route-mapper.gemspec
51
+ - spec/lib/sinatra/route_mapper_spec.rb
52
+ - spec/spec_helper.rb
53
+ homepage: https://github.com/letmein/sinatra-route-mapper
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.10
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Sinatra middleware
77
+ test_files:
78
+ - spec/lib/sinatra/route_mapper_spec.rb
79
+ - spec/spec_helper.rb