build-uri 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 875ee954e27285ed02e09319a4522ff214f0a79c
4
+ data.tar.gz: 7abb5ce2d4cac8a351a2b97825e09d7c8cb6bb8d
5
+ SHA512:
6
+ metadata.gz: 6867609819a69023dc1ecd8eda6a3ff87b55feac5a7ce46eeeb201ade4ee4df67c7c7bb56a30a23f2d88ed0fa6adcdee822ec5fcf2bfc19bede0c236668c6201
7
+ data.tar.gz: 91424aff5e447387a4e21742c568b72dcd55fa30492edf802fc1972b60040cc949b77b8cf8dc08464dda0d376d41d1cafd4f31d5c79dfd99d25b7bbec6bea5dc
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --format documentation
3
+ --backtrace
4
+ --warnings
5
+ --require spec_helper
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+ sudo: false
3
+ dist: trusty
4
+ cache: bundler
5
+ rvm:
6
+ - 2.1
7
+ - 2.2
8
+ - 2.3
9
+ - 2.4
10
+ - ruby-head
11
+ - jruby-head
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: "ruby-head"
15
+ - rvm: "jruby-head"
16
+ addons:
17
+ apt:
18
+ packages:
19
+ - graphviz
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in build-dependency.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ end
10
+
11
+ group :test do
12
+ gem 'simplecov'
13
+ gem 'coveralls', require: false
14
+ end
@@ -0,0 +1,9 @@
1
+
2
+ directories %w(lib spec)
3
+ clearing :on
4
+
5
+ guard :rspec, cmd: "bundle exec rspec" do
6
+ watch(%r{^spec/.+_spec\.rb$})
7
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
+ watch("spec/spec_helper.rb") { "spec" }
9
+ end
@@ -0,0 +1,81 @@
1
+ # Build::URI
2
+
3
+ `Build::URI` provides unform handling of file paths (`Build::URI::Relative`), URIs (`Build::URI::Absolute`) and triples (`Build::URI::Triple`).
4
+
5
+ [![Build Status](https://secure.travis-ci.org/ioquatix/build-uri.svg)](http://travis-ci.org/ioquatix/build-uri)
6
+ [![Code Climate](https://codeclimate.com/github/ioquatix/build-uri.svg)](https://codeclimate.com/github/ioquatix/build-uri)
7
+ [![Coverage Status](https://coveralls.io/repos/ioquatix/build-uri/badge.svg)](https://coveralls.io/r/ioquatix/build-uri)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'build-uri'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install build-uri
22
+
23
+ ## Usage
24
+
25
+ To parse an input:
26
+
27
+ ```ruby
28
+ uri = Build::URI[value]
29
+ ```
30
+
31
+ Is it a local file?
32
+
33
+ ```ruby
34
+ if uri.local?
35
+ File.read(uri.to_path)
36
+ else
37
+ # ... curl
38
+ end
39
+ ```
40
+
41
+ Concatenate paths:
42
+
43
+ ```ruby
44
+ root = Build::URI["http://www.google.com/search?q=awesome"]
45
+ path = Build::URI["/login"]
46
+
47
+ (root + path).to_s
48
+ # => "http://www.google.com/login?q=awesome"
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
58
+
59
+ ## License
60
+
61
+ Released under the MIT license.
62
+
63
+ Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
64
+
65
+ Permission is hereby granted, free of charge, to any person obtaining a copy
66
+ of this software and associated documentation files (the "Software"), to deal
67
+ in the Software without restriction, including without limitation the rights
68
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
69
+ copies of the Software, and to permit persons to whom the Software is
70
+ furnished to do so, subject to the following conditions:
71
+
72
+ The above copyright notice and this permission notice shall be included in
73
+ all copies or substantial portions of the Software.
74
+
75
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
76
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
77
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
78
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
79
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
80
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
81
+ THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
+ end
7
+
8
+ task :default => :spec
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ require_relative 'lib/build/uri/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "build-uri"
6
+ spec.version = Build::URI::VERSION
7
+ spec.authors = ["Samuel Williams"]
8
+ spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
+ spec.summary = %q{Handle absolute URIs, triples and file paths uniformly.}
10
+ spec.homepage = ""
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "rspec", "~> 3.4.0"
20
+ spec.add_development_dependency "rake"
21
+ end
@@ -0,0 +1,25 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative 'uri/version'
22
+
23
+ require_relative 'uri/absolute'
24
+ require_relative 'uri/relative'
25
+ require_relative 'uri/parser'
@@ -0,0 +1,87 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative 'base'
22
+
23
+ module Build
24
+ module URI
25
+ class Absolute < Struct.new(:scheme, :userinfo, :host, :path, :query, :fragment)
26
+ include Base
27
+
28
+ # A subset of RFC2396 specifically relevant to path based URIs. We are not interested in generic URIs such as mailto.
29
+ PARSER = %r{\A
30
+ ((?<scheme>[^:\/?\#]+):)
31
+ (\/\/
32
+ ((?<userinfo>[^\/?\#]+)@)?
33
+ (?<host>[^\/?\#]*)
34
+ )
35
+ (?<path>[^?\#]*)
36
+ (\?(?<query>[^\#]*))?
37
+ (\#(?<fragment>.*))?
38
+ \z}x.freeze
39
+
40
+ def absolute?
41
+ true
42
+ end
43
+
44
+ def local?
45
+ false
46
+ end
47
+
48
+ def to_s
49
+ buffer = String.new
50
+
51
+ if scheme
52
+ buffer << scheme << ':'
53
+ end
54
+
55
+ if host
56
+ buffer << '//'
57
+
58
+ if userinfo
59
+ buffer << userinfo << '@'
60
+ end
61
+
62
+ buffer << host
63
+ end
64
+
65
+ if path
66
+ buffer << path
67
+ end
68
+
69
+ if query
70
+ buffer << '?' << query
71
+ end
72
+
73
+ if fragment
74
+ buffer << '#' << fragment
75
+ end
76
+
77
+ return buffer
78
+ end
79
+
80
+ def self.parse(string)
81
+ if match = PARSER.match(string)
82
+ self.new(*match.values_at(*self.members)).freeze
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,70 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module Build
22
+ module URI
23
+ SEPARATOR = '/'.freeze
24
+
25
+ module Base
26
+ # @attr directory [Boolean] If true, we consider every path to represent a directory, even if there is no trailing slash. If false, basename of self will be ignored when joining.
27
+ def merge(other, directory: true)
28
+ if self.path.nil? || other.absolute?
29
+ return other
30
+ else
31
+ clone = self.dup
32
+
33
+ if other.path.start_with?(SEPARATOR)
34
+ clone.path = other.path
35
+ elsif directory
36
+ # We try to avoid ending up with more than one slash:
37
+ if self.path.end_with?(SEPARATOR)
38
+ clone.path = [self.path, other.path].join
39
+ else
40
+ clone.path = [self.path, other.path].join(SEPARATOR)
41
+ end
42
+ else
43
+ # The basename of a non-directory path is ignored when merged.
44
+ dirname, _, basename = self.path.rpartition(SEPARATOR)
45
+
46
+ clone.path = [dirname, other.path].join(SEPARATOR)
47
+ end
48
+
49
+ return clone.freeze
50
+ end
51
+ end
52
+
53
+ def + other
54
+ merge(URI[other])
55
+ end
56
+
57
+ def dirname
58
+ clone = self.dup
59
+
60
+ clone.path = self.path.rpartition(SEPARATOR).first
61
+
62
+ return clone
63
+ end
64
+
65
+ def basename
66
+ clone.path = self.path.rpartition(SEPARATOR).last
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'uri'
22
+
23
+ require_relative 'absolute'
24
+ require_relative 'relative'
25
+ require_relative 'triplet'
26
+
27
+ module Build
28
+ module URI
29
+ def self.parse(string)
30
+ Absolute.parse(string) || Triplet.parse(string) || Relative.new(string)
31
+ end
32
+
33
+ EMPTY = Relative.new(nil).freeze
34
+
35
+ def self.[](value)
36
+ case value
37
+ when Base
38
+ return value
39
+ when NilClass
40
+ return EMPTY
41
+ else
42
+ self.parse(value.to_s)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,42 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module Build
22
+ module URI
23
+ class Relative < Struct.new(:path)
24
+ include Base
25
+
26
+ def absolute?
27
+ false
28
+ end
29
+
30
+ def local?
31
+ true
32
+ end
33
+
34
+ alias to_s path
35
+
36
+ def to_path
37
+ # TODO Convert SEPARATOR to File::SEPARATOR?
38
+ @path
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module Build
22
+ module URI
23
+ class Triplet < Struct.new(:userinfo, :host, :path)
24
+ include Base
25
+
26
+ PARSER = %r{\A
27
+ (?:(?<userinfo>.+)@)?
28
+ (?<host>[\w.-]+)
29
+ :(?<path>.*)
30
+ \z}x.freeze
31
+
32
+ def local?
33
+ false
34
+ end
35
+
36
+ def to_s
37
+ buffer = String.new
38
+
39
+ if userinfo
40
+ buffer << userinfo << '@'
41
+ end
42
+
43
+ buffer << host << ':' << path
44
+
45
+ return buffer
46
+ end
47
+
48
+ def self.parse(string)
49
+ if match = PARSER.match(string)
50
+ self.new(*match.values_at(*self.members))
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module Build
22
+ module URI
23
+ VERSION = "1.0.0"
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ RSpec.describe Build::URI::Absolute do
22
+ describe "two absolute uris" do
23
+ subject {Build::URI.parse("http://localhost/a/b") + Build::URI.parse("http://localhost/c/d")}
24
+
25
+ shared_examples "valid absolute"
26
+
27
+ it "should result in other absolute url when concatenated" do
28
+ is_expected.to be == Build::URI.parse("http://localhost/c/d")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,56 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ RSpec.shared_context "parse uri" do |uri|
22
+ subject {Build::URI[uri]}
23
+
24
+ it "should parse" do
25
+ is_expected.to_not be_nil
26
+ end
27
+
28
+ it "should be homoiconic" do
29
+ expect(subject.to_s).to be == uri
30
+ end
31
+
32
+ it "shouldn't reparse uri" do
33
+ expect(Build::URI[subject]).to be_equal subject
34
+ end
35
+ end
36
+
37
+ RSpec.describe "git@github.com:ioquatix/build-uri" do
38
+ include_context "parse uri", description
39
+ include_examples "valid triplet"
40
+ end
41
+
42
+ RSpec.describe "http://www.google.com/search?q=doot" do
43
+ include_context "parse uri", description
44
+ include_examples "valid absolute"
45
+ end
46
+
47
+ RSpec.describe "/" do
48
+ include_context "parse uri", description
49
+ include_examples "valid relative"
50
+ end
51
+
52
+ RSpec.describe "foo/bar" do
53
+ include_context "parse uri", description
54
+ include_examples "valid relative"
55
+ end
56
+
@@ -0,0 +1,82 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ RSpec.describe Build::URI::Base do
22
+ let(:a) {Build::URI.parse("/a")}
23
+ let(:b) {Build::URI.parse("b")}
24
+
25
+ describe '#merge(directory: false)' do
26
+ subject {a.merge(b, directory: false)}
27
+
28
+ it "should merge ignoring basename" do
29
+ is_expected.to be == Build::URI.parse("/b")
30
+ end
31
+ end
32
+
33
+ describe '#merge(directory: true)' do
34
+ subject {a.merge(b, directory: true)}
35
+
36
+ it "should merge including basename" do
37
+ is_expected.to be == Build::URI.parse("/a/b")
38
+ end
39
+ end
40
+ end
41
+
42
+ RSpec.describe Build::URI::Relative do
43
+ describe "two relative paths" do
44
+ subject {Build::URI.parse("a/b") + Build::URI.parse("c/d")}
45
+
46
+ shared_examples "valid relative"
47
+
48
+ it "should concatenate paths" do
49
+ is_expected.to be == Build::URI.parse("a/b/c/d")
50
+ end
51
+ end
52
+
53
+ describe "two absolute paths" do
54
+ subject {Build::URI.parse("/a/b") + Build::URI.parse("/c/d")}
55
+
56
+ shared_examples "valid relative"
57
+
58
+ it "should be other absolute path when concatenated" do
59
+ is_expected.to be == Build::URI.parse("/c/d")
60
+ end
61
+ end
62
+
63
+ describe "absolute uri and relative path" do
64
+ subject {Build::URI.parse("http://localhost/a/b") + Build::URI.parse("c/d")}
65
+
66
+ shared_examples "valid absolute"
67
+
68
+ it "should concatenate paths" do
69
+ is_expected.to be == Build::URI.parse("http://localhost/a/b/c/d")
70
+ end
71
+ end
72
+
73
+ describe "absolute uri and absolute path" do
74
+ subject {Build::URI.parse("http://localhost/a/b") + Build::URI.parse("/c/d")}
75
+
76
+ shared_examples "valid absolute"
77
+
78
+ it "should be other absolute path when concatenated" do
79
+ is_expected.to be == Build::URI.parse("http://localhost/c/d")
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ RSpec.describe Build::URI::Triplet do
22
+ describe "absolute triplet and relative path" do
23
+ subject {Build::URI.parse("git@github.com:ioquatix") + Build::URI.parse("build-uri")}
24
+
25
+ shared_examples "valid triplet"
26
+
27
+ it "should concatenate paths" do
28
+ is_expected.to be == Build::URI.parse("git@github.com:ioquatix/build-uri")
29
+ end
30
+ end
31
+
32
+ describe "absolute triplet and absolute path" do
33
+ subject {Build::URI.parse("git@github.com:ioquatix") + Build::URI.parse("/forked/build-uri")}
34
+
35
+ shared_examples "valid triplet"
36
+
37
+ it "should concatenate paths" do
38
+ is_expected.to be == Build::URI.parse("git@github.com:/forked/build-uri")
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+
2
+ if ENV['COVERAGE']
3
+ begin
4
+ require 'simplecov'
5
+
6
+ SimpleCov.start do
7
+ add_filter "/spec/"
8
+ end
9
+
10
+ if ENV['TRAVIS']
11
+ require 'coveralls'
12
+ Coveralls.wear!
13
+ end
14
+ rescue LoadError
15
+ warn "Could not load simplecov: #{$!}"
16
+ end
17
+ end
18
+
19
+ require "bundler/setup"
20
+ require "build/uri"
21
+
22
+ RSpec.shared_examples "valid triplet" do
23
+ it "should be valid triplet" do
24
+ is_expected.to be_kind_of Build::URI::Triplet
25
+ end
26
+ end
27
+
28
+ RSpec.shared_examples "valid absolute" do
29
+ it "should be valid absolute" do
30
+ is_expected.to be_kind_of Build::URI::Absolute
31
+ end
32
+ end
33
+
34
+ RSpec.shared_examples "valid relative" do
35
+ it "sohuld be a valid relative" do
36
+ is_expected.to be_kind_of Build::URI::Relative
37
+ end
38
+ end
39
+
40
+ RSpec.configure do |config|
41
+ # Enable flags like --only-failures and --next-failure
42
+ config.example_status_persistence_file_path = ".rspec_status"
43
+
44
+ config.expect_with :rspec do |c|
45
+ c.syntax = :expect
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: build-uri
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-27 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.4.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ - samuel.williams@oriontransfer.co.nz
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Guardfile
67
+ - README.md
68
+ - Rakefile
69
+ - build-uri.gemspec
70
+ - lib/build/uri.rb
71
+ - lib/build/uri/absolute.rb
72
+ - lib/build/uri/base.rb
73
+ - lib/build/uri/parser.rb
74
+ - lib/build/uri/relative.rb
75
+ - lib/build/uri/triplet.rb
76
+ - lib/build/uri/version.rb
77
+ - spec/build/uri/absolute_spec.rb
78
+ - spec/build/uri/parser_spec.rb
79
+ - spec/build/uri/relative_spec.rb
80
+ - spec/build/uri/triplet_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: ''
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.6.10
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Handle absolute URIs, triples and file paths uniformly.
106
+ test_files:
107
+ - spec/build/uri/absolute_spec.rb
108
+ - spec/build/uri/parser_spec.rb
109
+ - spec/build/uri/relative_spec.rb
110
+ - spec/build/uri/triplet_spec.rb
111
+ - spec/spec_helper.rb