uri_template 0.1.2 → 0.1.3

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.1.3 - 15.11.2011
2
+ * BUGFIX: Draft7./ now concatenates literals correctly
3
+ * BUGFIX: Draft7.tokens is now public
4
+
1
5
  # 0.1.2 - 10.11.2011
2
6
  + added a new template-type: Colon
3
7
  this should allow (some day) to rails-like routing tables
data/lib/uri_template.rb CHANGED
@@ -245,5 +245,32 @@ module URITemplate
245
245
  def static_characters
246
246
  @static_characters ||= tokens.select(&:literal?).map{|t| t.string.size }.inject(0,:+)
247
247
  end
248
+
249
+ # Returns whether this uri-template is absolute.
250
+ # This is detected by checking for "://".
251
+ #
252
+ def absolute?
253
+ read_chars = ""
254
+
255
+ tokens.each do |token|
256
+ if token.expression?
257
+ read_chars << "x"
258
+ elsif token.literal?
259
+ read_chars << token.string
260
+ end
261
+ if read_chars =~ /^[a-z]+:\/\//i
262
+ return true
263
+ elsif read_chars =~ /(?<!:|\/)\/(?!\/)/
264
+ return false
265
+ end
266
+ end
267
+
268
+ return false
269
+ end
270
+
271
+ # Opposite of {#absolute?}
272
+ def relative?
273
+ !absolute?
274
+ end
248
275
 
249
276
  end
@@ -832,47 +832,32 @@ __REGEXP__
832
832
  # so we can strip one '/'
833
833
  return self.class.new( self.tokens[0..-2] + [ Literal.new(self.tokens.last.string[0..-2]) ] + other.tokens )
834
834
  end
835
+ elsif other.tokens.first.kind_of? Literal
836
+ # okay, this template does not end with /, but the next starts with a literal => merge them!
837
+ if other.tokens.first.string[0] == '/'
838
+ return self.class.new( self.tokens[0..-2] + [Literal.new(self.tokens.last.string + other.tokens.first.string)] + other.tokens[1..-1] )
839
+ else
840
+ return self.class.new( self.tokens[0..-2] + [Literal.new(self.tokens.last.string + '/' + other.tokens.first.string)] + other.tokens[1..-1] )
841
+ end
835
842
  end
836
843
  end
837
- if other.tokens.first.kind_of?(Expression::Path) or (other.tokens.first.kind_of?(Literal) and other.tokens.first.string[0] == '/')
844
+
845
+ if other.tokens.first.kind_of?(Literal)
846
+ if other.tokens.first.string[0] == '/'
847
+ return self.class.new( self.tokens + other.tokens )
848
+ else
849
+ return self.class.new( self.tokens + [Literal.new('/' + other.tokens.first.string)]+ other.tokens[1..-1] )
850
+ end
851
+ elsif other.tokens.first.kind_of?(Expression::Path)
838
852
  return self.class.new( self.tokens + other.tokens )
839
853
  else
840
854
  return self.class.new( self.tokens + [Literal.new('/')] + other.tokens )
841
855
  end
842
856
  end
843
857
 
844
-
845
- #
846
- # should be relative:
847
- # xxx ...
848
- # {xxx}x ...
849
- #
850
- # should not be relative:
851
- # {proto}:// ...
852
- # http:// ...
853
- # http{ssl}:// ...
854
- #
855
- def absolute?
856
- read_chars = ""
857
-
858
- tokens.each do |token|
859
- if token.kind_of? Expression
860
- if token.class::OPERATOR == ''
861
- read_chars << "x"
862
- else
863
- return false
864
- end
865
- elsif token.kind_of? Literal
866
- read_chars << token.string
867
- end
868
- if read_chars =~ /^[a-z]+:\/\//i
869
- return true
870
- elsif read_chars =~ /(?<!:|\/)\/(?!\/)/
871
- return false
872
- end
873
- end
874
-
875
- return false
858
+ # Returns an array containing a the template tokens.
859
+ def tokens
860
+ @tokens ||= tokenize!
876
861
  end
877
862
 
878
863
  protected
@@ -881,10 +866,6 @@ protected
881
866
  Tokenizer.new(pattern).to_a
882
867
  end
883
868
 
884
- def tokens
885
- @tokens ||= tokenize!
886
- end
887
-
888
869
  # @private
889
870
  def extract_matchdata(matchdata)
890
871
  bc = 0
data/uri_template.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'uri_template'
3
- s.version = '0.1.2'
4
- s.date = '2011-11-10'
3
+ s.version = '0.1.3'
4
+ s.date = '2011-11-15'
5
5
  s.authors = ["HannesG"]
6
6
  s.email = %q{hannes.georg@googlemail.com}
7
7
  s.summary = 'A templating system for URIs.'
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.1.2
4
+ version: 0.1.3
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-11-10 00:00:00.000000000Z
12
+ date: 2011-11-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &14750900 !ruby/object:Gem::Requirement
16
+ requirement: &26050760 !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: *14750900
24
+ version_requirements: *26050760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &14750460 !ruby/object:Gem::Requirement
27
+ requirement: &26050320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *14750460
35
+ version_requirements: *26050320
36
36
  description: ! 'A templating system for URIs, which implements http://tools.ietf.org/html/draft-gregorio-uritemplate-07
37
37
  . An implementation of an older version of that spec is known as addressable. This
38
38
  gem however is intended to be extended when newer specs evolve. For now only draft