sinatra-namespace 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ copyright (c) 2010 Konstantin Haase. All rights reserved.
2
+
3
+ Developed by: Konstantin Haase
4
+ http://github.com/rkh/big_band
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to
8
+ deal with the Software without restriction, including without limitation the
9
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ sell copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+ 1. Redistributions of source code must retain the above copyright notice,
13
+ this list of conditions and the following disclaimers.
14
+ 2. Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimers in the
16
+ documentation and/or other materials provided with the distribution.
17
+ 3. Neither the name of Konstantin Haase, nor the names of other contributors
18
+ may be used to endorse or promote products derived from this Software without
19
+ specific prior written permission.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27
+ WITH THE SOFTWARE.
data/README.md CHANGED
@@ -81,7 +81,7 @@ Modular style (you can of course use the `namespace` method there, too):
81
81
  end
82
82
 
83
83
  Wait, did that module turn into a namespace all by itself? No, actually it got turned into one by `Application` when it
84
- tried to call `prefix`, which is not defined. `Sinatra::Namspace` sets up `nested_method_missing` (from `monkey-lib`) to
84
+ tried to call `prefix`, which is not defined. `Sinatra::Namespace` sets up `nested_method_missing` (from `monkey-lib`) to
85
85
  catch that cases.
86
86
 
87
87
  You can influence that behavior by setting `auto_namespace`:
@@ -90,7 +90,7 @@ You can influence that behavior by setting `auto_namespace`:
90
90
  # enables auto namespacing, is default
91
91
  enable :auto_namespace
92
92
 
93
- # disables auto namespacing, is default
93
+ # disables auto namespacing
94
94
  disable :auto_namespace
95
95
 
96
96
  # triggers auto namespaceing only on prefix and get
@@ -47,7 +47,12 @@ module Sinatra
47
47
 
48
48
  def prefixed(verb, name = nil, options = {}, &block)
49
49
  name, options = nil, name if name.is_a? Hash and options.empty?
50
- path = prefix.to_s + name.to_s
50
+ if prefix.is_a? Regexp or name.is_a? Regexp
51
+ path = /#{prefix}#{name}/
52
+ path = /^#{path}$/ if base.is_a? Class
53
+ else
54
+ path = prefix.to_s + name.to_s
55
+ end
51
56
  application.send(:define_method, "#{verb} #{path}", &block)
52
57
  unbound_method, container = application.instance_method("#{verb} #{path}"), self
53
58
  if block.arity != 0
@@ -71,7 +76,7 @@ module Sinatra
71
76
  end
72
77
 
73
78
  def forward?(name)
74
- not Sinatra::NameError::DONT_FORWARD.include? name.to_s
79
+ not Sinatra::Namespace::DONT_FORWARD.include? name.to_s
75
80
  end
76
81
  end
77
82
 
@@ -99,7 +104,6 @@ module Sinatra
99
104
  end
100
105
 
101
106
  def namespace(prefix, merge = nil, &block)
102
- prefix = prefix.to_s
103
107
  if merge or (merge.nil? and merge_namespaces?)
104
108
  @namespaces ||= {}
105
109
  @namespaces[prefix] ||= namespace prefix, false
@@ -27,6 +27,25 @@ describe Sinatra::Namespace do
27
27
  browse_route(verb, "/foo").should be_ok
28
28
  browse_route(verb, "/foo").body.should == "bar" unless verb == :head
29
29
  end
30
+
31
+ it "allows regular expressions" do
32
+ app.namespace %r{/\d\d} do
33
+ send(verb) { "foo" }
34
+ namespace %r{/\d\d} do
35
+ send(verb) { "bar" }
36
+ end
37
+ namespace "/0000" do
38
+ send(verb) { "baz" }
39
+ end
40
+ end
41
+ browse_route(verb, '/20').should be_ok
42
+ browse_route(verb, '/20').body.should == "foo" unless verb == :head
43
+ browse_route(verb, '/20/20').should be_ok
44
+ browse_route(verb, '/20/20').body.should == "bar" unless verb == :head
45
+ browse_route(verb, '/20/0000').should be_ok
46
+ browse_route(verb, '/20/0000').body.should == "baz" unless verb == :head
47
+ browse_route(verb, '/20/200').should_not be_ok
48
+ end
30
49
  end
31
50
 
32
51
  describe :make_namespace do
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-namespace
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 13
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 4
8
- - 0
9
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Konstantin Haase
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-14 00:00:00 +02:00
18
+ date: 2010-06-04 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: monkey-lib
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ~>
26
28
  - !ruby/object:Gem::Version
29
+ hash: 15
27
30
  segments:
28
31
  - 0
29
32
  - 4
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: sinatra-sugar
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ~>
40
44
  - !ruby/object:Gem::Version
45
+ hash: 15
41
46
  segments:
42
47
  - 0
43
48
  - 4
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: sinatra-test-helper
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ~>
54
60
  - !ruby/object:Gem::Version
61
+ hash: 15
55
62
  segments:
56
63
  - 0
57
64
  - 4
@@ -63,23 +70,26 @@ dependencies:
63
70
  name: sinatra
64
71
  prerelease: false
65
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
66
74
  requirements:
67
- - - ">="
75
+ - - ~>
68
76
  - !ruby/object:Gem::Version
77
+ hash: 15
69
78
  segments:
79
+ - 1
70
80
  - 0
71
- - 9
72
- - 4
73
- version: 0.9.4
81
+ version: "1.0"
74
82
  type: :runtime
75
83
  version_requirements: *id004
76
84
  - !ruby/object:Gem::Dependency
77
85
  name: rspec
78
86
  prerelease: false
79
87
  requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
80
89
  requirements:
81
90
  - - ">="
82
91
  - !ruby/object:Gem::Version
92
+ hash: 27
83
93
  segments:
84
94
  - 1
85
95
  - 3
@@ -100,6 +110,7 @@ files:
100
110
  - spec/sinatra/namespace_spec.rb
101
111
  - spec/spec_helper.rb
102
112
  - README.md
113
+ - LICENSE
103
114
  has_rdoc: yard
104
115
  homepage: http://github.com/rkh/sinatra-namespace
105
116
  licenses: []
@@ -110,23 +121,27 @@ rdoc_options: []
110
121
  require_paths:
111
122
  - lib
112
123
  required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
113
125
  requirements:
114
126
  - - ">="
115
127
  - !ruby/object:Gem::Version
128
+ hash: 3
116
129
  segments:
117
130
  - 0
118
131
  version: "0"
119
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
120
134
  requirements:
121
135
  - - ">="
122
136
  - !ruby/object:Gem::Version
137
+ hash: 3
123
138
  segments:
124
139
  - 0
125
140
  version: "0"
126
141
  requirements: []
127
142
 
128
143
  rubyforge_project:
129
- rubygems_version: 1.3.6
144
+ rubygems_version: 1.3.7
130
145
  signing_key:
131
146
  specification_version: 3
132
147
  summary: Adds namespaces to Sinatra, allows namespaces to have local helpers (part of BigBand).