iuri 1.0.0

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: f823ae8478599ae553df7854ab74819fd56e1301
4
+ data.tar.gz: 81dc21e0b3899b2ddd6908f95fc5d0919e6ee861
5
+ SHA512:
6
+ metadata.gz: 131316b2a076b97a9d386651a9aa92f24f4f50506b9507b311c3956d06ddba0273836b6f7d03b6d981d9b49e2065f504404dc8f8de608e39ab7586c90668e7b5
7
+ data.tar.gz: 8b59b357b357509a98cf600e1e2b80133a7b3aefdf10eb27259bf73c9b67fa7f17e926e3fd6d29b90f4a7d752f8c366e63f49a6faa7b47681ab030800e974bf0
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iuri.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 LIFX Inc
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # IURI
2
+
3
+ Build complex URIs with chainability and immutability. If you're familiar
4
+ with URI then you already know how to use it.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'iuri'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install iuri
19
+
20
+ ## Usage
21
+
22
+ Change components of a URI using a hash. Changes are chainable and each
23
+ one returns a new instance.
24
+
25
+ Example:
26
+
27
+ uri1 = IURI.parse("https://user:secret@lifx.co")
28
+ uri2 = uri1.merge(path: "/api/v1/foos")
29
+ uri2.to_s # => "https://user:secret@lifx.co/api/v1/foos"
30
+
31
+ ## Tests
32
+
33
+ Run the entire test suite.
34
+
35
+ $ rake
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/tatey/iuri/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
44
+
45
+ ## Copyright
46
+
47
+ Copyright 2014 LIFX Inc. MIT License. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new :test do |test|
5
+ test.libs << 'test'
6
+ test.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task default: :test
data/iuri.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'iuri/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'iuri'
8
+ spec.version = IURI::VERSION
9
+ spec.authors = ['Tate Johnson']
10
+ spec.email = ['tate@lifx.co']
11
+ spec.summary = %q{Build complex URIs with chainability and immutability.}
12
+ spec.description = %q{Build complex URIs with chainability and immutability.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ end
data/lib/iuri.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'uri'
2
+ require 'iuri/version'
3
+
4
+ class IURI
5
+ def initialize(uri)
6
+ @uri = uri
7
+ end
8
+
9
+ def self.parse(string)
10
+ uri = URI.parse(string)
11
+ new(uri)
12
+ end
13
+
14
+ # Change components of a URI using a hash. Changes are chainable and
15
+ # each one returns a new instance.
16
+ #
17
+ # Example:
18
+ # uri1 = MergeableURI.parse("https://lifx.co")
19
+ # uri2 = uri1.merge(path: "/foo/bar")
20
+ # uri2.to_s # => "https://lifx.co/foo/bar"
21
+ #
22
+ # @param options [Hash] Components
23
+ # @return [MergeableURI] A new instance
24
+ def merge(options)
25
+ copy = @uri.dup
26
+ options.each do |key, value|
27
+ writer = :"#{key}="
28
+ if copy.respond_to?(writer)
29
+ copy.send(writer, value)
30
+ else
31
+ raise KeyError, "key not found: \"#{key}\""
32
+ end
33
+ end
34
+ self.class.new(copy)
35
+ end
36
+
37
+ def to_s
38
+ @uri.to_s
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ class IURI
2
+ VERSION = '1.0.0'
3
+ end
data/test/iuri_test.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'minitest/autorun'
2
+ require 'iuri'
3
+
4
+ class IURITest < Minitest::Test
5
+ def test_it_sets_known_components
6
+ uri1 = IURI.parse('http://lifx.co')
7
+ uri2 = uri1.merge(scheme: 'https', path: '/foo/bar', query: 'baz=true')
8
+
9
+ assert_equal 'https://lifx.co/foo/bar?baz=true', uri2.to_s
10
+ end
11
+
12
+ def test_it_raises_unknown_components
13
+ assert_raises(KeyError) do
14
+ IURI.parse('http://lifx.co').merge(combobulator: 42)
15
+ end
16
+ end
17
+
18
+ def test_it_is_a_copy
19
+ uri1 = IURI.parse('http://lifx.co')
20
+ uri2 = uri1.merge(path: '/foo/bar')
21
+
22
+ refute_same uri1, uri2
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iuri
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tate Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 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
+ description: Build complex URIs with chainability and immutability.
42
+ email:
43
+ - tate@lifx.co
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - iuri.gemspec
54
+ - lib/iuri.rb
55
+ - lib/iuri/version.rb
56
+ - test/iuri_test.rb
57
+ homepage: ''
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Build complex URIs with chainability and immutability.
81
+ test_files:
82
+ - test/iuri_test.rb
83
+ has_rdoc: