uri_template 0.6.0 → 0.7.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e795b18afed57cb37be55473035352b72840137
4
+ data.tar.gz: bc9b6c7926531fa76e6c5d2cbcbade14f5c32832
5
+ SHA512:
6
+ metadata.gz: 12d4f67c125ae1bb05054765563217ec63438793ea709f554d648f25d1ec30f437fd1854b784023516975c938ebf21263cc271a42c670097e4ba3c46c46f32e4
7
+ data.tar.gz: 3062ed310d22881fd560d9e8cfcfa7f8bab87c9e72a76adb8f32089d9a04b380f69e5f7b821f6f0799163639351014fa1609344bc840f289c93ff6dc178de7e0
@@ -1,4 +1,9 @@
1
- # 0.6.0 - TBD
1
+ # 0.7.0 - 21.03.2014
2
+
3
+ * [CHANGE] Licence is now MIT
4
+ * [ENHANCEMENT] partial expansion has now more features
5
+
6
+ # 0.6.0 - 09.08.2013
2
7
 
3
8
  * [FEATURE] partial expansion
4
9
  * [FEATURE] You can now pass variables as an Array to URITemplate#expand ( thanks to @bmaland )
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- URITemplate - a uri template library
2
- ========================
1
+ # URITemplate - a uri template library
3
2
 
4
3
  [![Build Status](https://secure.travis-ci.org/hannesg/uri_template.png)](http://travis-ci.org/hannesg/uri_template)
5
4
  [![Dependency Status](https://gemnasium.com/hannesg/uri_template.png)](https://gemnasium.com/hannesg/uri_template)
@@ -10,50 +9,54 @@ With URITemplate you can generate URIs based on simple templates and extract var
10
9
 
11
10
  From version 0.2.0, it will use escape_utils if available. This will significantly boost uri-escape/unescape performance if more characters need to be escaped ( may be slightly slower in trivial cases. working on that ... ), but does not run everywhere. To enable this, do the following:
12
11
 
13
- # escape_utils has to be loaded when uri_templates is loaded
14
- gem 'escape_utils'
15
- require 'escape_utils'
16
-
17
- gem 'uri_template'
18
- require 'uri_template'
19
-
20
- UriTemplate::Utils.using_escape_utils? #=> true
21
-
22
-
23
- Examples
24
- -------------------
25
-
26
- require 'uri_template'
27
-
28
- tpl = URITemplate.new('http://{host}{/segments*}/{file}{.extensions*}')
29
-
30
- # This will give: http://www.host.com/path/to/a/file.x.y
31
- tpl.expand('host'=>'www.host.com','segments'=>['path','to','a'],'file'=>'file','extensions'=>['x','y'])
32
-
33
- # This will give: { 'host'=>'www.host.com','segments'=>['path','to','a'],'file'=>'file','extensions'=>['x','y']}
34
- tpl.extract('http://www.host.com/path/to/a/file.x.y')
35
-
36
- # If you like colon templates more:
37
- tpl2 = URITemplate.new(:colon, '/:x/y')
38
-
39
- # This will give: {'x' => 'z'}
40
- tpl2.extract('/z/y')
41
-
42
- # This will give a new uri template with just the host expanded:
43
- tpl.expand_partial(host: "www.host.com")
44
-
45
- RFC 6570 Syntax
46
- --------------------
12
+ ```ruby
13
+ # escape_utils has to be loaded when uri_templates is loaded
14
+ gem 'escape_utils'
15
+ require 'escape_utils'
16
+
17
+ gem 'uri_template'
18
+ require 'uri_template'
19
+
20
+ URITemplate::Utils.using_escape_utils? #=> true
21
+ ```
22
+
23
+ ## Examples
24
+
25
+ ```ruby
26
+ require 'uri_template'
27
+
28
+ tpl = URITemplate.new('http://{host}{/segments*}/{file}{.extensions*}')
29
+
30
+ # This will give: http://www.host.com/path/to/a/file.x.y
31
+ tpl.expand('host'=>'www.host.com','segments'=>['path','to','a'],'file'=>'file','extensions'=>['x','y'])
32
+
33
+ # This will give: { 'host'=>'www.host.com','segments'=>['path','to','a'],'file'=>'file','extensions'=>['x','y']}
34
+ tpl.extract('http://www.host.com/path/to/a/file.x.y')
35
+
36
+ # If you like colon templates more:
37
+ tpl2 = URITemplate.new(:colon, '/:x/y')
38
+
39
+ # This will give: {'x' => 'z'}
40
+ tpl2.extract('/z/y')
41
+
42
+ # This will give a new uri template with just the host expanded:
43
+ tpl.expand_partial(host: "www.host.com")
44
+ ```
45
+
46
+ ## RFC 6570 Syntax
47
47
 
48
48
  The syntax defined by [RFC 6570]( http://tools.ietf.org/html/rfc6570 ) is pretty straight forward. Basically anything surrounded by curly brackets is interpreted as variable.
49
49
 
50
- URITemplate.new('{variable}').expand('variable' => 'value') #=> "value"
50
+ ```ruby
51
+ URITemplate.new('{variable}').expand('variable' => 'value') #=> "value"
52
+ ```
51
53
 
52
54
  The way variables are inserted can be modified using operators. The operator is the first character between the curly brackets. There are seven operators defined `#`, `+`, `;`, `?`, `&`, `/` and `.`. So if you want to create a form-style query do this:
53
55
 
54
- URITemplate.new('{?variable}').expand('variable' => 'value') #=> "?variable=value"
56
+ ```ruby
57
+ URITemplate.new('{?variable}').expand('variable' => 'value') #=> "?variable=value"
58
+ ```
55
59
 
56
- Benchmarks
57
- -----------------------
60
+ ## Benchmarks
58
61
 
59
62
  I have assembled one benchmark based on the uritemplate-test examples. You can find them in the "benchmarks" folder. The short result: uri_template is 2-10x faster than addressable on ruby 1.9.3.
@@ -1,19 +1,25 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
17
23
 
18
24
  # A base module for all implementations of a uri template.
19
25
  module URITemplate
@@ -1,19 +1,25 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
17
23
 
18
24
  require 'forwardable'
19
25
 
@@ -1,19 +1,25 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
17
23
 
18
24
  # A module which all non-literal tokens should include.
19
25
  module URITemplate::Expression
@@ -30,4 +36,4 @@ module URITemplate::Expression
30
36
  true
31
37
  end
32
38
 
33
- end
39
+ end
@@ -1,19 +1,25 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
17
23
 
18
24
  # A module which all literal tokens should include.
19
25
  module URITemplate::Literal
@@ -1,19 +1,25 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
17
23
 
18
24
  require 'strscan'
19
25
  require 'set'
@@ -319,7 +325,7 @@ __REGEXP__
319
325
  # @method expand_partial(variables = {})
320
326
  # Works like expand but keeps missing variables in place.
321
327
  # @example
322
- # URITemplate::RFC6570.new('{foo}').expand_partial('foo'=>'bar') #=> URITemplate::RFC6570.new('bar')
328
+ # URITemplate::RFC6570.new('{foo}').expand_partial('foo'=>'bar') #=> URITemplate::RFC6570.new('bar{foo}')
323
329
  # URITemplate::RFC6570.new('{undef}').expand_partial() #=> URITemplate::RFC6570.new('{undef}')
324
330
  #
325
331
  # @param variables [Hash,Array]
@@ -1,20 +1,25 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
17
-
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
18
23
  require 'uri_template/rfc6570'
19
24
 
20
25
  class URITemplate::RFC6570
@@ -75,20 +80,33 @@ class URITemplate::RFC6570
75
80
 
76
81
  def expand_partial( vars )
77
82
  result = []
78
- defined = false
83
+ follow_up = self.class::FOLLOW_UP
84
+ var_specs = []
79
85
  @variable_specs.each do | var, expand , max_length |
80
- defined ||= vars.key? var
81
- if Utils.def? vars[var]
82
- result.push(*expand_one(var, vars[var], expand, max_length))
86
+ if vars.key? var
87
+ unless var_specs.none?
88
+ result.push( follow_up.new( var_specs ) )
89
+ var_specs = []
90
+ end
91
+ unless result.none?
92
+ result.push( Literal.new(self.class::SEPARATOR) )
93
+ end
94
+ one = Array(expand_one(var, vars[var], expand, max_length))
95
+ result.push( Literal.new(one.join(self.class::SEPARATOR)))
83
96
  end
97
+ var_specs << [var,expand,max_length]
84
98
  end
85
- if result.any?
86
- return [ Literal.new(self.class::PREFIX + result.join(self.class::SEPARATOR)) ]
87
- elsif defined
88
- return []
89
- else
99
+ if result.none?
100
+ # no literal was emitted so far
90
101
  return [ self ]
91
102
  end
103
+ unless self.class::PREFIX.empty? || empty_literals?( result )
104
+ result.unshift( Literal.new(self.class::PREFIX) )
105
+ end
106
+ if var_specs.size != 0
107
+ result.push( follow_up.new( var_specs ) )
108
+ end
109
+ return result
92
110
  end
93
111
 
94
112
  def extract(position,matched)
@@ -261,12 +279,18 @@ class URITemplate::RFC6570
261
279
  [ self_pair(name, ary, max_length){|value| escape(value) } ]
262
280
  end
263
281
  end
282
+
283
+ def empty_literals?( list )
284
+ list.none?{|x| x.kind_of?(Literal) && !x.to_s.empty? }
285
+ end
264
286
  end
265
287
 
266
288
  require 'uri_template/rfc6570/expression/named'
267
289
  require 'uri_template/rfc6570/expression/unnamed'
268
290
 
269
291
  class Expression::Basic < Expression::Unnamed
292
+ FOLLOW_UP = self
293
+ BULK_FOLLOW_UP = self
270
294
  end
271
295
 
272
296
  class Expression::Reserved < Expression::Unnamed
@@ -274,6 +298,8 @@ class URITemplate::RFC6570
274
298
  CHARACTER_CLASS = CHARACTER_CLASSES[:unreserved_reserved_pct]
275
299
  OPERATOR = '+'.freeze
276
300
  BASE_LEVEL = 2
301
+ FOLLOW_UP = self
302
+ BULK_FOLLOW_UP = self
277
303
 
278
304
  def escape(x)
279
305
  Utils.escape_uri(Utils.object_to_param(x))
@@ -299,6 +325,8 @@ class URITemplate::RFC6570
299
325
  PREFIX = '#'.freeze
300
326
  OPERATOR = '#'.freeze
301
327
  BASE_LEVEL = 2
328
+ FOLLOW_UP = Expression::Reserved
329
+ BULK_FOLLOW_UP = Expression::Reserved
302
330
 
303
331
  def escape(x)
304
332
  Utils.escape_uri(Utils.object_to_param(x))
@@ -316,6 +344,8 @@ class URITemplate::RFC6570
316
344
  PREFIX = '.'.freeze
317
345
  OPERATOR = '.'.freeze
318
346
  BASE_LEVEL = 3
347
+ FOLLOW_UP = self
348
+ BULK_FOLLOW_UP = self
319
349
 
320
350
  end
321
351
 
@@ -325,6 +355,8 @@ class URITemplate::RFC6570
325
355
  PREFIX = '/'.freeze
326
356
  OPERATOR = '/'.freeze
327
357
  BASE_LEVEL = 3
358
+ FOLLOW_UP = self
359
+ BULK_FOLLOW_UP = self
328
360
 
329
361
  def starts_with_slash?
330
362
  true
@@ -339,27 +371,33 @@ class URITemplate::RFC6570
339
371
  PAIR_IF_EMPTY = false
340
372
  OPERATOR = ';'.freeze
341
373
  BASE_LEVEL = 3
374
+ FOLLOW_UP = self
375
+ BULK_FOLLOW_UP = self
342
376
 
343
377
  end
344
378
 
345
- class Expression::FormQuery < Expression::Named
379
+ class Expression::FormQueryContinuation < Expression::Named
346
380
 
347
381
  SEPARATOR = '&'.freeze
348
- PREFIX = '?'.freeze
349
- OPERATOR = '?'.freeze
382
+ PREFIX = '&'.freeze
383
+ OPERATOR = '&'.freeze
350
384
  BASE_LEVEL = 3
351
-
385
+ FOLLOW_UP = Expression::Basic
386
+ BULK_FOLLOW_UP = self
352
387
  end
353
388
 
354
- class Expression::FormQueryContinuation < Expression::Named
389
+ class Expression::FormQuery < Expression::Named
355
390
 
356
391
  SEPARATOR = '&'.freeze
357
- PREFIX = '&'.freeze
358
- OPERATOR = '&'.freeze
392
+ PREFIX = '?'.freeze
393
+ OPERATOR = '?'.freeze
359
394
  BASE_LEVEL = 3
395
+ FOLLOW_UP = Expression::Basic
396
+ BULK_FOLLOW_UP = Expression::FormQueryContinuation
360
397
 
361
398
  end
362
399
 
400
+
363
401
  # @private
364
402
  OPERATORS = {
365
403
  '' => Expression::Basic,
@@ -1,23 +1,31 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
17
23
 
18
24
  require 'uri_template/rfc6570'
19
25
 
20
- class URITemplate::RFC6570::Expression::Named < URITemplate::RFC6570::Expression
26
+ class URITemplate::RFC6570
27
+
28
+ class Expression::Named < Expression
21
29
 
22
30
  alias self_pair pair
23
31
 
@@ -54,6 +62,39 @@ class URITemplate::RFC6570::Expression::Named < URITemplate::RFC6570::Expression
54
62
  return source.join
55
63
  end
56
64
 
65
+ def expand_partial( vars )
66
+ result = []
67
+ rest = []
68
+ defined = false
69
+ @variable_specs.each do | var, expand , max_length |
70
+ if vars.key? var
71
+ if Utils.def? vars[var]
72
+ if result.any? && !self.class::SEPARATOR.empty?
73
+ result.push( Literal.new(self.class::SEPARATOR) )
74
+ end
75
+ one = expand_one(var, vars[var], expand, max_length)
76
+ result.push( Literal.new(Array(one).join(self.class::SEPARATOR)) )
77
+ end
78
+ if expand
79
+ rest << [var, expand, max_length]
80
+ else
81
+ result.push( self.class::FOLLOW_UP.new([[var,expand,max_length]]) )
82
+ end
83
+ else
84
+ rest.push( [var,expand,max_length] )
85
+ end
86
+ end
87
+ if result.any?
88
+ unless self.class::PREFIX.empty? || empty_literals?( result )
89
+ result.unshift( Literal.new(self.class::PREFIX) )
90
+ end
91
+ result.push( self.class::BULK_FOLLOW_UP.new(rest) ) if rest.size != 0
92
+ return result
93
+ else
94
+ return [ self ]
95
+ end
96
+ end
97
+
57
98
  private
58
99
 
59
100
  def extracted_nil
@@ -69,4 +110,5 @@ private
69
110
  end
70
111
  end
71
112
 
72
- end
113
+ end
114
+ end
@@ -1,19 +1,25 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
17
23
 
18
24
  require 'uri_template/rfc6570'
19
25
 
@@ -1,19 +1,25 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
17
23
 
18
24
  require 'uri_template/rfc6570'
19
25
 
@@ -114,4 +120,4 @@ class URITemplate::RFC6570
114
120
 
115
121
  end
116
122
 
117
- end
123
+ end
@@ -1,19 +1,25 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
17
23
 
18
24
  # This should make it possible to do basic analysis independently from the concrete type.
19
25
  # Usually the submodules {URITemplate::Literal} and {URITemplate::Expression} are used.
@@ -1,19 +1,26 @@
1
1
  # -*- encoding : utf-8 -*-
2
- # This program is free software: you can redistribute it and/or modify
3
- # it under the terms of the Affero GNU General Public License as published by
4
- # the Free Software Foundation, either version 3 of the License, or
5
- # (at your option) any later version.
2
+ # The MIT License (MIT)
6
3
  #
7
- # This program is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU General Public License for more details.
4
+ # Copyright (c) 2011-2014 Hannes Georg
11
5
  #
12
- # You should have received a copy of the GNU General Public License
13
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
14
12
  #
15
- # (c) 2011 - 2012 by Hannes Georg
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
16
15
  #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
17
24
  module URITemplate
18
25
 
19
26
  # An awesome little helper which helps iterating over a string.
@@ -1,17 +1,19 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'uri_template'
3
- s.version = '0.6.0'
3
+ s.version = '0.7.0'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
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
9
  s.description = 'A templating system for URIs, which implements RFC6570 and Colon based URITemplates in a clean and straight forward way.'
10
-
10
+
11
11
  s.require_paths = ['lib']
12
-
12
+
13
+ s.license = 'MIT'
14
+
13
15
  s.files = Dir.glob('lib/**/**/*.rb') + ['uri_template.gemspec', 'README.md', 'CHANGELOG.md']
14
-
16
+
15
17
  s.add_development_dependency 'multi_json'
16
18
  s.add_development_dependency 'rspec'
17
19
  s.add_development_dependency 'yard'
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri_template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
5
- prerelease:
4
+ version: 0.7.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - HannesG
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-09 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: multi_json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: yard
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: bundler
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  description: A templating system for URIs, which implements RFC6570 and Colon based
@@ -98,42 +87,43 @@ executables: []
98
87
  extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
101
- - lib/uri_template/utils.rb
90
+ - CHANGELOG.md
91
+ - README.md
92
+ - lib/uri_template.rb
102
93
  - lib/uri_template/colon.rb
103
94
  - lib/uri_template/expression.rb
104
- - lib/uri_template/token.rb
105
- - lib/uri_template/rfc6570.rb
106
95
  - lib/uri_template/literal.rb
107
- - lib/uri_template/rfc6570/regex_builder.rb
108
- - lib/uri_template/rfc6570/expression/unnamed.rb
109
- - lib/uri_template/rfc6570/expression/named.rb
96
+ - lib/uri_template/rfc6570.rb
110
97
  - lib/uri_template/rfc6570/expression.rb
111
- - lib/uri_template.rb
98
+ - lib/uri_template/rfc6570/expression/named.rb
99
+ - lib/uri_template/rfc6570/expression/unnamed.rb
100
+ - lib/uri_template/rfc6570/regex_builder.rb
101
+ - lib/uri_template/token.rb
102
+ - lib/uri_template/utils.rb
112
103
  - uri_template.gemspec
113
- - README.md
114
- - CHANGELOG.md
115
104
  homepage: http://github.com/hannesg/uri_template
116
- licenses: []
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
117
108
  post_install_message:
118
109
  rdoc_options: []
119
110
  require_paths:
120
111
  - lib
121
112
  required_ruby_version: !ruby/object:Gem::Requirement
122
- none: false
123
113
  requirements:
124
- - - ! '>='
114
+ - - ">="
125
115
  - !ruby/object:Gem::Version
126
116
  version: '0'
127
117
  required_rubygems_version: !ruby/object:Gem::Requirement
128
- none: false
129
118
  requirements:
130
- - - ! '>='
119
+ - - ">="
131
120
  - !ruby/object:Gem::Version
132
121
  version: '0'
133
122
  requirements: []
134
123
  rubyforge_project:
135
- rubygems_version: 1.8.23
124
+ rubygems_version: 2.2.1
136
125
  signing_key:
137
- specification_version: 3
126
+ specification_version: 4
138
127
  summary: A templating system for URIs.
139
128
  test_files: []
129
+ has_rdoc: