uri-builder 0.1.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
+ SHA256:
3
+ metadata.gz: 79be4540f2657d7541d12a963a291725e09616a69419766c4837bce4fcf1427e
4
+ data.tar.gz: 056da9654ee9d8e6ef02aa9d506875c96bf7b3e7101bff7ae7d63dcc60a57930
5
+ SHA512:
6
+ metadata.gz: 9dd79c9d2bf080139d01e3cc73b056bec41ce63328f1c5867e78f994580db79e73adec4e62aa791ac4eb8ff11886ba0bdc44e3cc1ef02c8b0dec7874ed2d9912
7
+ data.tar.gz: b472b4e23463a4096ccb9d4c562f607b8057b6d476db67ca0eb904f312d570635404679c2cc3938ad580fb34c7fc9242f58c5697fc5612abb643b4c15063fc44
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in uri-builder.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ uri-builder (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.3)
10
+ diff-lcs (1.5.0)
11
+ method_source (1.0.0)
12
+ pry (0.14.1)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rake (13.0.6)
16
+ rspec (3.10.0)
17
+ rspec-core (~> 3.10.0)
18
+ rspec-expectations (~> 3.10.0)
19
+ rspec-mocks (~> 3.10.0)
20
+ rspec-core (3.10.2)
21
+ rspec-support (~> 3.10.0)
22
+ rspec-expectations (3.10.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-mocks (3.10.3)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-support (3.10.3)
29
+
30
+ PLATFORMS
31
+ x86_64-darwin-20
32
+
33
+ DEPENDENCIES
34
+ pry
35
+ rake (~> 13.0)
36
+ rspec (~> 3.0)
37
+ uri-builder!
38
+
39
+ BUNDLED WITH
40
+ 2.3.13
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # URI::Builder
2
+
3
+ URI builder makes working with URLs in Ruby a little less awkward by chaining methods calls that alter the URL. It looks like this:
4
+
5
+ ```ruby
6
+ URI.build("https://www.example.com/api/v1").path("/api/v2").query(search: "great books").uri
7
+ ```
8
+
9
+ Compare that to:
10
+
11
+ ```ruby
12
+ uri = URI("https://www.example.com/api/v1")
13
+ uri.path = "/api/v2"
14
+ uri.query = URI.encode_www_form(search: "great books")
15
+ uri
16
+ ```
17
+
18
+ There's even a shortcut for working with URLs from ENV vars:
19
+
20
+ ```ruby
21
+ URI.env("API_URL").path("/people/search").query(first_name: "Brad")
22
+ ```
23
+
24
+ Compare that to:
25
+
26
+ ```ruby
27
+ uri = URI ENV.fetch("API_URL")
28
+ uri.path = "/people/search"
29
+ uri.query = URI.encode_www_form(first_name: "Brad")
30
+ uri
31
+ ```
32
+
33
+ Each chain creates a duplicate of the original URL, so you can transform away without worrying about thrashing the original URL object.
34
+
35
+ ## Installation
36
+
37
+ Install the gem and add to the application's Gemfile by executing:
38
+
39
+ $ bundle add uri-builder
40
+
41
+ If bundler is not being used to manage dependencies, install the gem by executing:
42
+
43
+ $ gem install uri-builder
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rocketshipio/uri-builder.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module URI
4
+ module Build
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "builder/version"
4
+ require "uri"
5
+
6
+ module URI
7
+ module Builder
8
+ class Error < StandardError; end
9
+
10
+ class DSL
11
+ attr_reader :uri
12
+
13
+ def initialize(uri)
14
+ @uri = uri.clone
15
+ end
16
+
17
+ [:host, :scheme, :path, :query, :fragment, :port].each do |property|
18
+ define_method property do |value|
19
+ wrap property, value
20
+ end
21
+ end
22
+
23
+ def query(value)
24
+ value = case value
25
+ when Hash
26
+ URI.encode_www_form value
27
+ else
28
+ value
29
+ end
30
+
31
+ wrap :query, value
32
+ end
33
+
34
+ def to_s
35
+ uri.to_s
36
+ end
37
+
38
+ private
39
+ def wrap(property, value)
40
+ @uri.send "#{property}=", value
41
+ self
42
+ end
43
+ end
44
+ end
45
+
46
+ def build
47
+ Builder::DSL.new self
48
+ end
49
+
50
+ def self.build(value)
51
+ URI(value).build
52
+ end
53
+
54
+ def self.env(key, default = nil)
55
+ build ENV.fetch key, default
56
+ end
57
+ end
@@ -0,0 +1 @@
1
+ require "uri/builder"
@@ -0,0 +1,6 @@
1
+ module URI
2
+ module Build
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/uri/builder/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "uri-builder"
7
+ spec.version = URI::Build::VERSION
8
+ spec.authors = ["Brad Gessler"]
9
+ spec.email = ["bradgessler@gmail.com"]
10
+
11
+ spec.summary = "Build URIs via chains"
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/rocketshipio/url-builder"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["changelog_uri"] = spec.homepage
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uri-builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brad Gessler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Build URIs via chains
14
+ email:
15
+ - bradgessler@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - README.md
24
+ - Rakefile
25
+ - lib/uri-builder.rb
26
+ - lib/uri/builder.rb
27
+ - lib/uri/builder/version.rb
28
+ - sig/uri/transform.rbs
29
+ - uri-transform.gemspec
30
+ homepage: https://github.com/rocketshipio/url-builder
31
+ licenses: []
32
+ metadata:
33
+ allowed_push_host: https://rubygems.org
34
+ homepage_uri: https://github.com/rocketshipio/url-builder
35
+ source_code_uri: https://github.com/rocketshipio/url-builder
36
+ changelog_uri: https://github.com/rocketshipio/url-builder
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.2.3
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Build URIs via chains
56
+ test_files: []