sinatra-snap 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -7,13 +7,13 @@ build URLs and perform parameter substitution.
7
7
 
8
8
  Install the gem:
9
9
 
10
- sudo gem install snap
10
+ sudo gem install sinatra-snap
11
11
 
12
12
  Then require it in your application and use away!
13
13
 
14
14
  require 'rubygems'
15
15
  require 'sinatra'
16
- require 'snap'
16
+ require 'sinatra-snap'
17
17
 
18
18
  paths :add => '/add/:addend/:augend',
19
19
  :sum => '/sum/:addend/:augend',
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -25,45 +25,48 @@ module Sinatra
25
25
  private :verify_type_of
26
26
  end
27
27
 
28
+ module UrlBuilder
29
+ def with(*values)
30
+ if self.instance_of? Regexp
31
+ process_regex_replacement(values)
32
+ else
33
+ process_string_replacement(values)
34
+ end
35
+ end
36
+
37
+ def process_regex_replacement(values)
38
+ url = String.new(self.source)
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
43
+ end
44
+
45
+ def process_string_replacement(values)
46
+ if %r{/(\*)}.match self
47
+ replacement_pattern = %r{/(\*)}
48
+ else
49
+ replacement_pattern = %r{/?(:\S+?)(?:/|$)}
50
+ end
51
+ build_url_from(replacement_pattern, values)
52
+ end
53
+
54
+ def build_url_from(replacement_pattern, values)
55
+ url = String.new(self)
56
+ scan(replacement_pattern).each_with_index do | placeholder, index |
57
+ url.sub!(Regexp.new(Regexp.escape(placeholder[0])), values[index].to_s)
58
+ end
59
+ url
60
+ end
61
+
62
+ private :process_regex_replacement, :process_string_replacement, :build_url_from
63
+ end
64
+
28
65
  module PathBuilderSupport
29
66
  def path_to path_name
30
67
  pattern = self.class.named_paths[path_name]
31
- puts "----------> " + path_name.to_s
32
- pattern.instance_eval do
33
- def with(*values)
34
- if self.instance_of? Regexp
35
- process_regex_replacement(values)
36
- else
37
- process_string_replacement(values)
38
- end
39
- end
40
-
41
- def process_regex_replacement(values)
42
- url = String.new(self.source)
43
- self.source.scan(%r{\(.+?\)}).each_with_index do | placeholder, index |
44
- url.sub!(Regexp.new(Regexp.escape(placeholder)), values[index].to_s)
45
- end
46
- url
47
- end
48
-
49
- def process_string_replacement(values)
50
- if %r{/(\*)}.match self
51
- replacement_pattern = %r{/(\*)}
52
- else
53
- replacement_pattern = %r{/?(:\S+?)(?:/|$)}
54
- end
55
- build_url_from(replacement_pattern, values)
56
- end
57
-
58
- def build_url_from(replacement_pattern, values)
59
- url = String.new(self)
60
- scan(replacement_pattern).each_with_index do | placeholder, index |
61
- url.sub!(Regexp.new(Regexp.escape(placeholder[0])), values[index].to_s)
62
- end
63
- url
64
- end
65
- end
66
- pattern
68
+ raise ArgumentError.new("Unknown path ':#{path_name.to_s}'") if pattern == nil
69
+ pattern.extend UrlBuilder
67
70
  end
68
71
  end
69
72
 
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.0"
5
+ s.version = "0.3.1"
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-06}
9
+ s.date = %q{2010-03-08}
10
10
  s.email = %q{bcarlso@gmail.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -20,16 +20,16 @@ Gem::Specification.new do |s|
20
20
  "Rakefile",
21
21
  "VERSION",
22
22
  "examples/named_route_example.rb",
23
- "lib/sinatra/named_path_support.rb",
24
23
  "lib/sinatra-snap.rb",
24
+ "lib/sinatra/named_path_support.rb",
25
25
  "sinatra-snap.gemspec",
26
26
  "spec/snap_spec.rb",
27
27
  "spec/spec_helper.rb"
28
28
  ]
29
- s.homepage = %q{http://github.com/bcarlso/sinatra-snap}
29
+ s.homepage = %q{http://github.com/bcarlso/snap}
30
30
  s.rdoc_options = ["--charset=UTF-8"]
31
31
  s.require_paths = ["lib"]
32
- s.rubygems_version = %q{1.3.5}
32
+ s.rubygems_version = %q{1.3.6}
33
33
  s.summary = %q{Sinatra NAmed Path support}
34
34
  s.test_files = [
35
35
  "spec/snap_spec.rb",
data/spec/snap_spec.rb CHANGED
@@ -89,4 +89,8 @@ describe "Snap helper methods for building URLs" do
89
89
  @app.path :say => '/say/*/to/*'
90
90
  @app.new.path_to(:say).with('hi', 'bob').should == '/say/hi/to/bob'
91
91
  end
92
+
93
+ it "should raise a friendly error when the path doesn't exist" do
94
+ lambda { @app.new.path_to(:unknown) }.should raise_error(ArgumentError)
95
+ end
92
96
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
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-06 00:00:00 -06:00
17
+ date: 2010-03-08 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -35,13 +35,13 @@ files:
35
35
  - Rakefile
36
36
  - VERSION
37
37
  - examples/named_route_example.rb
38
- - lib/sinatra/named_path_support.rb
39
38
  - lib/sinatra-snap.rb
39
+ - lib/sinatra/named_path_support.rb
40
40
  - sinatra-snap.gemspec
41
41
  - spec/snap_spec.rb
42
42
  - spec/spec_helper.rb
43
43
  has_rdoc: true
44
- homepage: http://github.com/bcarlso/sinatra-snap
44
+ homepage: http://github.com/bcarlso/snap
45
45
  licenses: []
46
46
 
47
47
  post_install_message: