sinatra-mapper 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.
- data/README.md +21 -0
- data/lib/sinatra/mapper.rb +44 -0
- metadata +80 -0
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Sinatra plugin that allows to easily prefix all routes within a scope. Basicall porting back the map functionality from Ramaze
|
2
|
+
|
3
|
+
How to get started:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'sinatra/base'
|
7
|
+
require 'sinatra/mapper'
|
8
|
+
|
9
|
+
module MyApp < Sinatra::Base
|
10
|
+
register Sinatra::Mapper
|
11
|
+
|
12
|
+
map '/api/1.0'
|
13
|
+
|
14
|
+
get '/foo'
|
15
|
+
"Bar #{request.path_info}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
With such an application going to /api/1.0/foo should display "Bar /api/1.0/foo"
|
21
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
# This module provides a way to add a prefix
|
4
|
+
# to all routes within the scope
|
5
|
+
module Sinatra
|
6
|
+
module Mapper
|
7
|
+
# Set the prefix to be used for all routes in the scope
|
8
|
+
def map(prefix)
|
9
|
+
# TODO remove a possible trailing /
|
10
|
+
@prefix = prefix
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(path, opts={}, &block) #:nodoc
|
14
|
+
super("#{@prefix}#{path}", opts, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def put(path, opts={}, &block) #:nodoc
|
18
|
+
super("#{@prefix}#{path}", opts, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def post(path, opts={}, &block) #:nodoc
|
22
|
+
super("#{@prefix}#{path}", opts, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(path, opts={}, &block) #:nodoc
|
26
|
+
super("#{@prefix}#{path}", opts, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def head(path, opts={}, &block) #:nodoc
|
30
|
+
super("#{@prefix}#{path}", opts, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def options(path, opts={}, &block) #:nodoc
|
34
|
+
super("#{@prefix}#{path}", opts, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def patch(path, opts={}, &block) #:nodoc
|
38
|
+
super("#{@prefix}#{path}", opts, &block)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
register Mapper
|
43
|
+
end
|
44
|
+
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-mapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Jerome Poichet
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2011-10-25 00:00:00 -07:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: sinatra
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
version: 1.1.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description:
|
35
|
+
email:
|
36
|
+
- poitch@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- README.md
|
45
|
+
- lib/sinatra/mapper.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: https://github.com/poitch/sinatra-mapper
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --inline-source
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.7
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Sinatra plugin that allows to easily prefix all routes within a scope. Basicall porting back the map functionality from Ramaze
|
79
|
+
test_files: []
|
80
|
+
|