url_builder 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1b8b72829b787ec5055b35e86442c636ec2ac0a407df01d3ab42b5c886fda301
4
+ data.tar.gz: c2974c6ca969693e7c7d6f9de9007d6c3f4a0e71d558cd106777fea66d7e0707
5
+ SHA512:
6
+ metadata.gz: fca4e15976d4a029a08d1319fa3b23851cc83fbf609ecac9db84d6cd9a5fd53cf7f8db0afab03db6f07d38743bf75913c6c697ce37e8618c7171650e210ff649
7
+ data.tar.gz: acaa931863a6557d83e998400f487ab67bd9c49baa59b43b9a15035c8ee1b1179d34492b59c83ba083ce7fc78da0e8e71c6ae15fbdfc3832b2daae6cbad634b5
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - 'spec/**/*.rb'
18
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-07-05
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in url_builder.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ url_builder (0.1.0)
5
+ activesupport (~> 7.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (7.0.3)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ ast (2.4.2)
16
+ concurrent-ruby (1.1.10)
17
+ diff-lcs (1.5.0)
18
+ i18n (1.10.0)
19
+ concurrent-ruby (~> 1.0)
20
+ json (2.6.2)
21
+ minitest (5.16.2)
22
+ parallel (1.22.1)
23
+ parser (3.1.2.0)
24
+ ast (~> 2.4.1)
25
+ rainbow (3.1.1)
26
+ rake (13.0.6)
27
+ regexp_parser (2.5.0)
28
+ rexml (3.2.5)
29
+ rspec (3.11.0)
30
+ rspec-core (~> 3.11.0)
31
+ rspec-expectations (~> 3.11.0)
32
+ rspec-mocks (~> 3.11.0)
33
+ rspec-core (3.11.0)
34
+ rspec-support (~> 3.11.0)
35
+ rspec-expectations (3.11.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.11.0)
38
+ rspec-mocks (3.11.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.11.0)
41
+ rspec-support (3.11.0)
42
+ rubocop (1.31.1)
43
+ json (~> 2.3)
44
+ parallel (~> 1.10)
45
+ parser (>= 3.1.0.0)
46
+ rainbow (>= 2.2.2, < 4.0)
47
+ regexp_parser (>= 1.8, < 3.0)
48
+ rexml (>= 3.2.5, < 4.0)
49
+ rubocop-ast (>= 1.18.0, < 2.0)
50
+ ruby-progressbar (~> 1.7)
51
+ unicode-display_width (>= 1.4.0, < 3.0)
52
+ rubocop-ast (1.18.0)
53
+ parser (>= 3.1.1.0)
54
+ ruby-progressbar (1.11.0)
55
+ tzinfo (2.0.4)
56
+ concurrent-ruby (~> 1.0)
57
+ unicode-display_width (2.2.0)
58
+
59
+ PLATFORMS
60
+ x86_64-darwin-20
61
+
62
+ DEPENDENCIES
63
+ minitest (~> 5.0)
64
+ rake (~> 13.0)
65
+ rspec (~> 3.11)
66
+ rubocop (~> 1.21)
67
+ url_builder!
68
+
69
+ BUNDLED WITH
70
+ 2.3.13
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # UrlBuilder
2
+
3
+ A simple ruby implementation of the builder pattern to create urls.
4
+ Supports dynamically adding path segments and query parameters as well as custom path segment separator characters.
5
+
6
+ ## Installation
7
+
8
+ Install the gem and add to the application's Gemfile by executing:
9
+
10
+ $ bundle add url_builder
11
+
12
+ If bundler is not being used to manage dependencies, install the gem by executing:
13
+
14
+ $ gem install url_builder
15
+
16
+ ## Usage
17
+
18
+ Instantiate the builder class with the base url and then add segments and query params as needed.
19
+
20
+ builder = UrlBuilder::Builder.new(base_url: 'www.example.com')
21
+ builder.add_segment("foo")
22
+ builder.add_segment("bar")
23
+ builder.add_query_param("key", "value")
24
+ builder.to_s # "www.example.com/foo/bar?key=value"
25
+
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/url_builder.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ begin
6
+ require "rspec/core/rake_task"
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ rescue StandardError
9
+ nil
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[spec rubocop]
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_support/core_ext"
5
+
6
+ module UrlBuilder
7
+ # A builder class to construct a url with path segments and query params
8
+ class Builder
9
+ # @param [String] base_url the base url to use. Must include the protocol
10
+ # @param [String] separator - optional path segment separator to use, defaults to '/'
11
+ # @param [Hash] query_params - optional query params to use
12
+ def initialize(base_url:, separator: "/", query_params: {})
13
+ @base_url = base_url
14
+ @separator = separator
15
+ @query_params = query_params.with_indifferent_access
16
+ @path_segments = []
17
+ end
18
+
19
+ # Add a path segment to the url
20
+ # @param [String] segment the path segment to add
21
+ # @return [void]
22
+ def add_segment(segment)
23
+ @path_segments << segment
24
+ end
25
+
26
+ # Add a query param to the url
27
+ # @param [String] key the key of the query param
28
+ # @param [String] value the value of the query param
29
+ # @return [void]
30
+ def add_query_param(key: "", value: "")
31
+ @query_params[key] = value
32
+ end
33
+
34
+ # Build the url to a string
35
+ # @return [String] the url
36
+ def to_s
37
+ path = @path_segments.filter(&:present?).join(@separator)
38
+ query_string = @query_params.filter { |k, v| k.present? && v.present? }.map { |k, v| "#{k}=#{v}" }.join("&")
39
+ url = @base_url
40
+ url += @separator + path if path.present?
41
+ url += "?#{query_string}" if query_string.present?
42
+ url
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UrlBuilder
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "url_builder/version"
4
+ require_relative "url_builder/builder"
5
+
6
+ # Module for namespacing the UrlBuilder to avoid naming conflicts
7
+ module UrlBuilder
8
+ end
@@ -0,0 +1,4 @@
1
+ module UrlBuilder
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/url_builder/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "url_builder"
7
+ spec.version = UrlBuilder::VERSION
8
+ spec.authors = ["Sean Dickinson"]
9
+ spec.email = ["contact@seandickinson.dev"]
10
+
11
+ spec.summary = "A Ruby Class to create URLs using the builder pattern"
12
+ spec.description = "See the github page for more details"
13
+ spec.homepage = "https://github.com/atinybeardedman/url-builder"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/atinybeardedman/url-builder"
19
+ spec.metadata["changelog_uri"] = "https://github.com/atinybeardedman/url-builder/blob/main/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "rspec", "~> 3.11"
33
+ spec.add_dependency "activesupport", "~> 7.0"
34
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: url_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sean Dickinson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '7.0'
41
+ description: See the github page for more details
42
+ email:
43
+ - contact@seandickinson.dev
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".rubocop.yml"
50
+ - CHANGELOG.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/url_builder.rb
57
+ - lib/url_builder/builder.rb
58
+ - lib/url_builder/version.rb
59
+ - sig/url_builder.rbs
60
+ - url_builder.gemspec
61
+ homepage: https://github.com/atinybeardedman/url-builder
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ homepage_uri: https://github.com/atinybeardedman/url-builder
66
+ source_code_uri: https://github.com/atinybeardedman/url-builder
67
+ changelog_uri: https://github.com/atinybeardedman/url-builder/blob/main/CHANGELOG.md
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.6.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.3.3
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: A Ruby Class to create URLs using the builder pattern
87
+ test_files: []