uri_template 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,13 +21,13 @@ module URITemplate
21
21
  # Initialize with a regexp and pass a string to :each.
22
22
  # It will yield a string or a MatchData
23
23
  class RegexpEnumerator
24
-
24
+
25
25
  include Enumerable
26
-
26
+
27
27
  def initialize(regexp)
28
28
  @regexp = regexp
29
29
  end
30
-
30
+
31
31
  def each(str)
32
32
  return Enumerator.new(self,:each,str) unless block_given?
33
33
  rest = str
@@ -49,19 +49,19 @@ module URITemplate
49
49
  end
50
50
  return self
51
51
  end
52
-
52
+
53
53
  end
54
54
 
55
55
  # This error will be raised whenever an object could not be converted to a param string.
56
56
  class Unconvertable < StandardError
57
-
57
+
58
58
  attr_reader :object
59
-
59
+
60
60
  def initialize(object)
61
61
  @object = object
62
62
  super("Could not convert the given object (#{Object.instance_method(:inspect).bind(@object).call() rescue '<????>'}) to a param since it doesn't respond to :to_param or :to_s.")
63
63
  end
64
-
64
+
65
65
  end
66
66
 
67
67
  # A collection of some utility methods.
@@ -69,12 +69,12 @@ module URITemplate
69
69
  # I will use the escape_utils library if available, but runs happily without.
70
70
  #
71
71
  module Utils
72
-
72
+
73
73
  KCODE_UTF8 = (Regexp::KCODE_UTF8 rescue 0)
74
-
74
+
75
75
  # Bundles some string encoding methods.
76
76
  module StringEncoding
77
-
77
+
78
78
  # @method to_ascii(string)
79
79
  # converts a string to ascii
80
80
  #
@@ -85,7 +85,7 @@ module URITemplate
85
85
  def to_ascii_encode(str)
86
86
  str.encode(Encoding::ASCII)
87
87
  end
88
-
88
+
89
89
  # @method to_utf8(string)
90
90
  # converts a string to utf8
91
91
  #
@@ -96,15 +96,15 @@ module URITemplate
96
96
  def to_utf8_encode(str)
97
97
  str.encode(Encoding::UTF_8)
98
98
  end
99
-
99
+
100
100
  def to_ascii_fallback(str)
101
101
  str
102
102
  end
103
-
103
+
104
104
  def to_utf8_fallback(str)
105
105
  str
106
106
  end
107
-
107
+
108
108
  if "".respond_to?(:encode)
109
109
  # @private
110
110
  alias_method :to_ascii, :to_ascii_encode
@@ -116,98 +116,97 @@ module URITemplate
116
116
  # @private
117
117
  alias_method :to_utf8, :to_utf8_fallback
118
118
  end
119
-
119
+
120
120
  public :to_ascii
121
121
  public :to_utf8
122
-
122
+
123
123
  end
124
-
124
+
125
125
  module Escaping
126
-
126
+
127
127
  # A pure escaping module, which implements escaping methods in pure ruby.
128
128
  # The performance is acceptable, but could be better with escape_utils.
129
129
  module Pure
130
-
130
+
131
131
  include StringEncoding
132
-
132
+
133
133
  # @private
134
134
  URL_ESCAPED = /([^A-Za-z0-9\-\._])/.freeze
135
-
135
+
136
136
  # @private
137
137
  URI_ESCAPED = /([^A-Za-z0-9!$&'()*+,.\/:;=?@\[\]_~])/.freeze
138
-
138
+
139
139
  # @private
140
- PCT = /%(\h\h)/.freeze
141
-
140
+ PCT = /%([0-9a-fA-F]{2})/.freeze
141
+
142
142
  def escape_url(s)
143
143
  to_utf8(s.to_s).gsub(URL_ESCAPED){
144
144
  '%'+$1.unpack('H2'*$1.bytesize).join('%').upcase
145
145
  }
146
146
  end
147
-
147
+
148
148
  def escape_uri(s)
149
149
  to_utf8(s.to_s).gsub(URI_ESCAPED){
150
150
  '%'+$1.unpack('H2'*$1.bytesize).join('%').upcase
151
151
  }
152
152
  end
153
-
153
+
154
154
  def unescape_url(s)
155
155
  to_utf8( s.to_s.gsub('+',' ').gsub(PCT){
156
156
  $1.to_i(16).chr
157
157
  } )
158
158
  end
159
-
159
+
160
160
  def unescape_uri(s)
161
161
  to_utf8( s.to_s.gsub(PCT){
162
162
  $1.to_i(16).chr
163
163
  })
164
164
  end
165
-
165
+
166
166
  def using_escape_utils?
167
167
  false
168
168
  end
169
-
169
+
170
170
  end
171
-
171
+
172
172
  if defined? EscapeUtils
173
-
173
+
174
174
  # A escaping module, which is backed by escape_utils.
175
175
  # The performance is good, espacially for strings with many escaped characters.
176
176
  module EscapeUtils
177
-
177
+
178
178
  include StringEncoding
179
-
179
+
180
180
  include ::EscapeUtils
181
-
181
+
182
182
  def using_escape_utils?
183
183
  true
184
184
  end
185
-
185
+
186
186
  def escape_url(s)
187
187
  super(to_utf8(s)).gsub('+','%20')
188
188
  end
189
-
189
+
190
190
  def escape_uri(s)
191
191
  super(to_utf8(s))
192
192
  end
193
-
193
+
194
194
  def unescape_url(s)
195
195
  super(to_ascii(s))
196
196
  end
197
-
197
+
198
198
  def unescape_uri(s)
199
199
  super(to_ascii(s))
200
200
  end
201
-
201
+
202
202
  end
203
-
203
+
204
204
  end
205
-
206
-
205
+
207
206
  end
208
-
207
+
209
208
  include StringEncoding
210
-
209
+
211
210
  if Escaping.const_defined? :EscapeUtils
212
211
  include Escaping::EscapeUtils
213
212
  puts "Using escape_utils." if $VERBOSE
@@ -215,7 +214,7 @@ module URITemplate
215
214
  include Escaping::Pure
216
215
  puts "Not using escape_utils." if $VERBOSE
217
216
  end
218
-
217
+
219
218
  # Converts an object to a param value.
220
219
  # Tries to call :to_param and then :to_s on that object.
221
220
  # @raise Unconvertable if the object could not be converted.
@@ -237,8 +236,7 @@ module URITemplate
237
236
  rescue NoMethodError
238
237
  raise Unconvertable.new(object)
239
238
  end
240
-
241
-
239
+
242
240
  # Returns true when the given value is an array and it only consists of arrays with two items.
243
241
  # This useful when using a hash is not ideal, since it doesn't allow duplicate keys.
244
242
  # @example
@@ -274,9 +272,9 @@ module URITemplate
274
272
  return x
275
273
  end
276
274
  end
277
-
275
+
278
276
  extend self
279
-
277
+
280
278
  end
281
279
 
282
280
  end
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'uri_template'
3
- s.version = '0.2.0'
4
- s.date = '2011-12-03'
3
+ s.version = '0.2.1'
4
+ s.date = '2011-12-30'
5
5
  s.authors = ["HannesG"]
6
6
  s.email = %q{hannes.georg@googlemail.com}
7
7
  s.summary = 'A templating system for URIs.'
8
8
  s.homepage = 'http://github.com/hannesg/uri_template'
9
- s.description = 'A templating system for URIs, which implements http://tools.ietf.org/html/draft-gregorio-uritemplate-07 . An implementation of an older version of that spec is known as addressable. This gem however is intended to be extended when newer specs evolve. For now only draft 7 is supported. Downside: not for 1.8.7.'
9
+ s.description = 'A templating system for URIs, which implements http://tools.ietf.org/html/draft-gregorio-uritemplate-07 . An implementation of an older version of that spec is known as addressable. This gem however is intended to be extended when newer specs evolve. For now only draft 7 and a simple colon based format are supported.'
10
10
 
11
11
  s.require_paths = ['lib']
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri_template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-03 00:00:00.000000000 Z
12
+ date: 2011-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &17186480 !ruby/object:Gem::Requirement
16
+ requirement: &7325660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *17186480
24
+ version_requirements: *7325660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &17185740 !ruby/object:Gem::Requirement
27
+ requirement: &7325220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *17185740
35
+ version_requirements: *7325220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &17184760 !ruby/object:Gem::Requirement
38
+ requirement: &7324800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *17184760
46
+ version_requirements: *7324800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &17195720 !ruby/object:Gem::Requirement
49
+ requirement: &7324380 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,11 +54,11 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *17195720
58
- description: ! 'A templating system for URIs, which implements http://tools.ietf.org/html/draft-gregorio-uritemplate-07
57
+ version_requirements: *7324380
58
+ description: A templating system for URIs, which implements http://tools.ietf.org/html/draft-gregorio-uritemplate-07
59
59
  . An implementation of an older version of that spec is known as addressable. This
60
60
  gem however is intended to be extended when newer specs evolve. For now only draft
61
- 7 is supported. Downside: not for 1.8.7.'
61
+ 7 and a simple colon based format are supported.
62
62
  email: hannes.georg@googlemail.com
63
63
  executables: []
64
64
  extensions: []