sinatra-snap 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sinatra/named_path_support.rb +23 -23
- data/sinatra-snap.gemspec +2 -2
- data/spec/snap_spec.rb +5 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
@@ -7,7 +7,7 @@ module Sinatra
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def paths(paths)
|
10
|
-
paths.keys.each { |
|
10
|
+
paths.keys.each { | key | verify_type_of(key) }
|
11
11
|
named_paths.merge!(paths)
|
12
12
|
end
|
13
13
|
|
@@ -26,40 +26,40 @@ module Sinatra
|
|
26
26
|
end
|
27
27
|
|
28
28
|
module UrlBuilder
|
29
|
+
SPLAT = %r{(\*)}
|
30
|
+
NAMED_PARAMETER = %r{/?(:\S+?)(?:/|$)}
|
31
|
+
REGEXP_GROUP = %r{\(.+?\)}
|
32
|
+
|
29
33
|
def with(*values)
|
30
34
|
if self.instance_of? Regexp
|
31
|
-
|
35
|
+
replace_regex_with(values)
|
32
36
|
else
|
33
|
-
|
37
|
+
replace_string_with(values)
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
37
|
-
def
|
38
|
-
|
39
|
-
url.scan(%r{\(.+?\)}).each_with_index do | placeholder, index |
|
40
|
-
url.sub!(Regexp.new(Regexp.escape(placeholder)), values[index].to_s)
|
41
|
-
end
|
42
|
-
url
|
41
|
+
def replace_regex_with(values)
|
42
|
+
perform_substitution_using(self.source, REGEXP_GROUP, values)
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
replacement_pattern = %r{/?(:\S+?)(?:/|$)}
|
45
|
+
def perform_substitution_using(url, replacement_pattern, values)
|
46
|
+
string = String.new(url)
|
47
|
+
string.scan(replacement_pattern).each_with_index do | placeholder, index |
|
48
|
+
string.sub!(Regexp.new(Regexp.escape(placeholder.first)), values[index].to_s)
|
50
49
|
end
|
51
|
-
|
50
|
+
string
|
52
51
|
end
|
53
|
-
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
url.sub!(Regexp.new(Regexp.escape(placeholder[0])), values[index].to_s)
|
58
|
-
end
|
59
|
-
url
|
52
|
+
|
53
|
+
def replace_string_with(values)
|
54
|
+
replacement_pattern = route_defined_using_splat? ? SPLAT : NAMED_PARAMETER
|
55
|
+
perform_substitution_using(self, replacement_pattern, values)
|
60
56
|
end
|
61
57
|
|
62
|
-
|
58
|
+
def route_defined_using_splat?
|
59
|
+
SPLAT.match self
|
60
|
+
end
|
61
|
+
|
62
|
+
private :replace_regex_with, :replace_string_with, :route_defined_using_splat?, :perform_substitution_using
|
63
63
|
end
|
64
64
|
|
65
65
|
module PathBuilderSupport
|
data/sinatra-snap.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{sinatra-snap}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["bcarlso"]
|
9
|
-
s.date = %q{2010-03-
|
9
|
+
s.date = %q{2010-03-13}
|
10
10
|
s.email = %q{bcarlso@gmail.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
data/spec/snap_spec.rb
CHANGED
@@ -90,6 +90,11 @@ describe "Snap helper methods for building URLs" do
|
|
90
90
|
@app.new.path_to(:say).with('hi', 'bob').should == '/say/hi/to/bob'
|
91
91
|
end
|
92
92
|
|
93
|
+
it "should still support splat syntax" do
|
94
|
+
@app.path :say => '/download/*.*'
|
95
|
+
@app.new.path_to(:say).with('path/to/file', 'xml').should == '/download/path/to/file.xml'
|
96
|
+
end
|
97
|
+
|
93
98
|
it "should raise a friendly error when the path doesn't exist" do
|
94
99
|
lambda { @app.new.path_to(:unknown) }.should raise_error(ArgumentError)
|
95
100
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- bcarlso
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-13 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|