uri-tag 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b241db45979bbe1fabdc5e0f1b4ffd8112e5544
4
+ data.tar.gz: 9dcd554347684dc47581c54a7dfccf557da2feab
5
+ SHA512:
6
+ metadata.gz: 134b8f9b06eabed847d377505d70822e65d23f40a678e940bb812773ce88b989e898bfc28084ce6289b11a422a11fd40c45b26cde97d84bce4bf2a20ac9f0b69
7
+ data.tar.gz: ca4f4666fb83aa120a2f509d272986342d3b17a78862821ff094a8ad745b9710381bbddeb52e82bfb1c3994a6a3d35a980818966669dc7219f92d274e42e46ae
data/BSDL ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (C) 2014 KITAITI Makoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
@@ -0,0 +1,7 @@
1
+ URI::Tag CHANGE LOG
2
+ ===================
3
+
4
+ 0.0.1
5
+ -----
6
+
7
+ * Initial release
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by KITAITI Makoto <KitaitiMakoto@gmail.com>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/README.markdown ADDED
@@ -0,0 +1,58 @@
1
+ URI::Tag
2
+ ========
3
+
4
+ This library extends standard bundled URI library to parse and build tag scheme URI defined in [RFC 4151][rfc4151].
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Install it yourself as:
10
+
11
+ $ gem install uri-tag
12
+
13
+ Or add this line to your application's Gemfile:
14
+
15
+ gem 'uri-tag', :require => 'uri/tag'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Usage
22
+ -----
23
+
24
+ require 'uri/tag'
25
+
26
+ tag_uri = URI.parse('tag:example.org,2014-06-06:KitaitiMakoto:#ruby')
27
+ tag_uri.scheme # => tag
28
+ tag_uri.authority # => example.org
29
+ tag_uri.date # => 2014-06-06
30
+ tag_uri.specific # => KitaitiMakoto:
31
+ tag_uri.fragment # => ruby
32
+
33
+ another_tag = URI::Tag.build(['example.org', '2014-06-06', 'KitaitiMakoto:', 'ruby'])
34
+ another_tag == tag_uri # => true
35
+
36
+ See also
37
+ --------
38
+
39
+ * [RFC 4151][rfc4151] The 'tag' URI Scheme
40
+ * [tag-uri][] - Tag scheme implementation based on [Addressable][addressable]
41
+
42
+ License
43
+ -------
44
+
45
+ The same to Ruby's. See the file COPYING.
46
+
47
+ Contributing
48
+ ------------
49
+
50
+ 1. Clone it ( https://gitorious.org/uri-ext/uri-tag/clone )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Merge Request
55
+
56
+ [rfc4151]: http://www.ietf.org/rfc/rfc4151.txt
57
+ [tag-uri]: https://github.com/yb66/tag-uri
58
+ [addressable]: https://github.com/sporkmonger/addressable
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems/tasks'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new do |task|
8
+ task.test_files = Gem::Specification.load(File.join(__dir__, 'uri-tag.gemspec')).test_files
9
+ end
10
+
11
+ Gem::Tasks.new
12
+ Rake::RDocTask.new do |task|
13
+ spec = Gem::Specification.load(File.join(__dir__, 'uri-tag.gemspec'))
14
+ task.rdoc_files = spec.require_paths.inject([]) {|files, dir| files + Dir.glob("#{dir}/**/*.rb")} + spec.extra_rdoc_files
15
+ task.main = 'README.markdown'
16
+ end
data/lib/uri/tag.rb ADDED
@@ -0,0 +1,124 @@
1
+ require 'uri/generic'
2
+
3
+ module URI
4
+ class Tag < Generic
5
+ COMPONENT = [:scheme, :authority, :date, :specific, :fragment].freeze
6
+
7
+ DNSCOMP_PATTERN = "(?:[#{PATTERN::ALNUM}](?:[#{PATTERN::ALNUM}|\\-]*[#{PATTERN::ALNUM}])?)".freeze
8
+ DNSNAME_PATTERN = "(?:#{DNSCOMP_PATTERN}(?:\\.#{DNSCOMP_PATTERN})*)".freeze
9
+ AUTHORITY_PATTERN = "(?:[#{PATTERN::ALNUM}|\\-\\._]+@)?#{DNSNAME_PATTERN}".freeze
10
+ DATE_PATTERN = '\d{4}(?:\-\d{2}(?:\-\d{2})?)?'.freeze
11
+ UNRESERVED_PATTERN = "#{PATTERN::ALNUM}\\-\\._~".freeze
12
+ SUB_DELIMS_PATTERN = '!$&\'\(\)*+,;='.freeze
13
+ PCHAR_PATTERN = "#{UNRESERVED_PATTERN}#{PATTERN::ESCAPED}#{SUB_DELIMS_PATTERN}:@".freeze
14
+ SPECIFIC_PATTERN = "[#{PCHAR_PATTERN}/?]*".freeze
15
+ TAG_REGEXP = Regexp.new("
16
+ \\A
17
+ (?<authority>#{AUTHORITY_PATTERN})
18
+ ,
19
+ (?<date>#{DATE_PATTERN})
20
+ :
21
+ (?<specific>#{SPECIFIC_PATTERN})
22
+ \\z
23
+ ", Regexp::EXTENDED).freeze
24
+
25
+ def self.build(args)
26
+ tmp = Util.make_components_hash(self, args)
27
+
28
+ tmp[:opaque] = '' << tmp[:authority] << ',' << tmp[:date] << ':'
29
+
30
+ if tmp[:specific]
31
+ tmp[:opaque] << tmp[:specific]
32
+ end
33
+
34
+ return super(tmp)
35
+ end
36
+
37
+ attr_reader :authority, :date, :specific, :fragment
38
+
39
+ def initialize(*arg)
40
+ super(*arg)
41
+
42
+ self.opaque = @opaque
43
+ end
44
+
45
+ def tagging_entity
46
+ authority + ',' + date
47
+ end
48
+
49
+ def authority=(value)
50
+ check_authority(value)
51
+ set_authority(value)
52
+ value
53
+ end
54
+
55
+ def date=(value)
56
+ check_date(value)
57
+ set_date(value)
58
+ value
59
+ end
60
+
61
+ def specific=(value)
62
+ check_specific(value)
63
+ set_specific(value)
64
+ value
65
+ end
66
+
67
+ def opaque=(value)
68
+ check_opaque(value)
69
+
70
+ if TAG_REGEXP =~ value
71
+ self.authority = $~['authority']
72
+ self.date = $~['date']
73
+ self.specific = $~['specific']
74
+ else
75
+ raise InvalidURIError, "bad URI(authority nor date not set?): #{self}" # raise InvalidURIError rather than InvalidComponentError, just because URI::Generic#check_opaque does so
76
+ end
77
+
78
+ set_opaque(value)
79
+ value
80
+ end
81
+
82
+ protected
83
+
84
+ def set_authority(authority)
85
+ @authority = authority
86
+ end
87
+
88
+ def set_date(date)
89
+ @date = date
90
+ end
91
+
92
+ def set_specific(specific)
93
+ @specific = specific
94
+ end
95
+
96
+ private
97
+
98
+ def check_authority(value)
99
+ if value !~ /\A(?:#{AUTHORITY_PATTERN})\z/o
100
+ raise InvalidComponentError, "bad component(expected authority component: #{value})"
101
+ end
102
+
103
+ return true
104
+ end
105
+
106
+ def check_date(value)
107
+ if value !~ /\A(?:#{DATE_PATTERN}\z)/o
108
+ raise InvalidComponentError, "bad component(expected date component: #{value})"
109
+ end
110
+
111
+ return true
112
+ end
113
+
114
+ def check_specific(value)
115
+ if value !~ /\A#{SPECIFIC_PATTERN}\z/o
116
+ raise InvalidComponentError, "bac component(expected specific component: #{value})"
117
+ end
118
+
119
+ return true
120
+ end
121
+ end
122
+
123
+ @@schemes['TAG'] = Tag
124
+ end
@@ -0,0 +1,137 @@
1
+ require 'test/unit'
2
+ require 'uri/tag'
3
+
4
+ module URI
5
+
6
+ class TestTag < Test::Unit::TestCase
7
+ def setup
8
+ @uri = URI.parse('tag:example.com,2000:')
9
+ end
10
+
11
+ def test_pattern
12
+ assert_match /#{Tag::DNSNAME_PATTERN}/, 'sub-domain.example.net'
13
+ assert_match /#{Tag::AUTHORITY_PATTERN}/, 'sub-domainexample.net'
14
+ assert_match /#{Tag::AUTHORITY_PATTERN}/, 'admin+ml@sub-domainexample.net'
15
+ assert_match /#{Tag::DATE_PATTERN}/, '2014'
16
+ assert_match /#{Tag::DATE_PATTERN}/, '2014-05'
17
+ assert_match /#{Tag::DATE_PATTERN}/, '2014-05-31'
18
+ end
19
+
20
+ def test_parse
21
+ uri = URI.parse('tag:example.net,2014:specific?query#fragment')
22
+
23
+ assert_equal 'tag', uri.scheme
24
+ assert_equal 'example.net', uri.authority
25
+ assert_equal '2014', uri.date
26
+ assert_equal 'specific?query', uri.specific
27
+ assert_equal 'fragment', uri.fragment
28
+ assert_equal 'example.net,2014:specific?query', uri.opaque
29
+
30
+ assert_nil uri.host
31
+ assert_nil uri.path
32
+ assert_nil uri.port
33
+ assert_nil uri.query
34
+ assert_nil uri.registry
35
+
36
+ %w[
37
+ tag:
38
+ tag:example.net
39
+ tag:example.net,2014
40
+ ].each do |uri_str|
41
+ assert_raise InvalidURIError do
42
+ URI.parse uri_str
43
+ end
44
+ end
45
+ end
46
+
47
+ def test_build
48
+ tag = nil
49
+ assert_nothing_raised do
50
+ tag = URI::Tag.build(['example.org', '2014', 'uri-tag', 'test'])
51
+ end
52
+ assert_equal 'example.org', tag.authority
53
+ assert_equal '2014', tag.date
54
+ assert_equal 'uri-tag', tag.specific
55
+ assert_equal 'test', tag.fragment
56
+ assert_equal 'example.org,2014:uri-tag', tag.opaque
57
+ assert_equal 'tag:example.org,2014:uri-tag#test', tag.to_s
58
+ end
59
+
60
+ def test_compopnent
61
+ assert_equal [:scheme, :authority, :date, :specific, :fragment], @uri.component
62
+ end
63
+
64
+ def test_authority
65
+ [
66
+ '',
67
+ ' exapmle.net '
68
+ ].each do |authority|
69
+ assert_raise InvalidComponentError do
70
+ @uri.authority = authority
71
+ end
72
+ end
73
+ end
74
+
75
+ def test_date
76
+ %w[
77
+ 20
78
+ 2014/06/04
79
+ 2014-06-04T00:00
80
+ ].each do |date|
81
+ assert_raise InvalidComponentError do
82
+ @uri.date = date
83
+ end
84
+ end
85
+ end
86
+
87
+ def test_specific
88
+ @uri.specific = 'sp%20+'
89
+ assert_equal 'sp%20+', @uri.specific
90
+ assert_raise InvalidComponentError do
91
+ @uri.specific = '#frag'
92
+ end
93
+ end
94
+
95
+ def test_opaque
96
+ @uri.fragment = 'frag'
97
+ @uri.opaque = 'example.org,2015:speci?fic'
98
+ assert_equal 'example.org,2015:speci?fic', @uri.opaque
99
+ assert_equal 'example.org', @uri.authority
100
+ assert_equal '2015', @uri.date
101
+ assert_equal 'speci?fic', @uri.specific
102
+ assert_equal 'frag', @uri.fragment
103
+ [
104
+ nil,
105
+ ''
106
+ ].each do |str|
107
+ assert_raise InvalidURIError do
108
+ @uri.opaque = nil
109
+ end
110
+ end
111
+ end
112
+
113
+ def test_fragment
114
+ assert_raise InvalidComponentError do
115
+ @uri.fragment = 'sp ce'
116
+ end
117
+ end
118
+
119
+ def test_port
120
+ assert_nil @uri.default_port
121
+ assert_raise InvalidURIError do
122
+ @uri.port = 80
123
+ end
124
+ end
125
+
126
+ def test_equal
127
+ assert(URI.parse('tag:example.com,2000:') == URI.parse('tag:example.com,2000:'))
128
+ assert(URI.parse('tag:example.com,2000:') != URI.parse('tag:EXAMPLE.COM,2000:'))
129
+ assert(URI.parse('tag:example.com,2000:') != URI.parse('tag:example.com,2000-01-01:'))
130
+ end
131
+
132
+ def test_route_from
133
+ skip
134
+ end
135
+ end
136
+
137
+ end
data/uri-tag.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "uri-tag"
3
+ spec.version = '0.0.1'
4
+ spec.authors = ["KITAITI Makoto"]
5
+ spec.email = ["KitaitiMakoto@gmail.com"]
6
+ spec.summary = %q{This library extends standard bundled URI library to parse and build tag scheme URI defined in RFC 4151.}
7
+ spec.homepage = "https://gitorious.org/uri-ext"
8
+ spec.license = "Ruby"
9
+
10
+ spec.test_files = ['test/uri/test_uri-tag.rb']
11
+ spec.require_paths = ["lib"]
12
+ spec.extra_rdoc_files = %w[README.markdown CHANGELOG.markdown COPYING BSDL]
13
+ spec.files = spec.require_paths.inject([]) {|files, dir|
14
+ files + Dir.glob("#{dir}/**/*.rb")
15
+ } +
16
+ spec.test_files +
17
+ spec.extra_rdoc_files +
18
+ %w[uri-tag.gemspec Rakefile]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rubygems-tasks"
23
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uri-tag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - KITAITI Makoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubygems-tasks
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - KitaitiMakoto@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files:
61
+ - README.markdown
62
+ - CHANGELOG.markdown
63
+ - COPYING
64
+ - BSDL
65
+ files:
66
+ - BSDL
67
+ - CHANGELOG.markdown
68
+ - COPYING
69
+ - README.markdown
70
+ - Rakefile
71
+ - lib/uri/tag.rb
72
+ - test/uri/test_uri-tag.rb
73
+ - uri-tag.gemspec
74
+ homepage: https://gitorious.org/uri-ext
75
+ licenses:
76
+ - Ruby
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: This library extends standard bundled URI library to parse and build tag
98
+ scheme URI defined in RFC 4151.
99
+ test_files:
100
+ - test/uri/test_uri-tag.rb