rack-joint 0.3.3 → 0.3.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee257b799f66a7c26ac7f2c84c21cae1db7b2d43dd7c119ef79bf644b9d529b5
4
- data.tar.gz: b9d746c446d687b39edadf90078a02449675f0952a57b142eb2e784656be933a
3
+ metadata.gz: 0141cddd5e1ef68701c51e0764c3567f5aaba781690376045555ba69e36d0f2e
4
+ data.tar.gz: 8bc87b56895863b25aeeb1e665c59f3187bc3374040635eaccae3d1dbc3e86f4
5
5
  SHA512:
6
- metadata.gz: a3b15942200d64afa3af22f76e89d5ac26bb75b95994c941c82fed88fa8de33a9f6830ec06f4f9e821df2d22c6ff500681fd50c14363f418f731dfc490ed780e
7
- data.tar.gz: a95a55acbde20af0026cd4e5d9db0d67a7c201428868476844dbdf8d69a604cb73e78f3fa711cc3ec4f56e383f9ee6bf8070955ce9474fe85278ec440ac7454f
6
+ metadata.gz: 70e64306e8ce1d02f0adae9e77eb3c2e1a7ec2b271ac7498c632ffc95bb89e2e56c1fca3d6332e86298bb38bfa8936bf3a68c365c8786d2613b3b11d8c923380
7
+ data.tar.gz: e287349d64b491b119911494155db46dd91c30a88035980018a37350ac11efd86a9520dc32a3ca8501bd7d7f9408413f711a7fd41172fbce221a5b4fd93b94d4
@@ -0,0 +1,33 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ # https://docs.github.com/en/actions/reference/events-that-trigger-workflows
12
+ push:
13
+ branches: '*'
14
+ pull_request:
15
+ types: [opened, synchronize, reopened]
16
+
17
+ jobs:
18
+ test:
19
+
20
+ runs-on: ubuntu-latest
21
+ strategy:
22
+ matrix:
23
+ ruby-version: ['2.7', '3.0', '3.1', '3.2']
24
+
25
+ steps:
26
+ - uses: actions/checkout@v3
27
+ - name: Set up Ruby
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby-version }}
31
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
32
+ - name: Run tests
33
+ run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ### 0.3.5
6
+ * Add Ruby 3.1 and 3.2 test and specify Rack version. [#21](https://github.com/akito19/rack-joint/pull/21)
7
+
8
+ ### 0.3.4 (2019-03-25)
9
+ * Allow query parameters when request URLs have them. [#18](https://github.com/akito19/rack-joint/pull/18)
10
+
5
11
  ### 0.3.3 (2019-01-19)
6
12
  * Support Bundler2. [#15](https://github.com/akito19/rack-joint/pull/15)
7
13
 
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
- require 'uri'
3
-
4
2
  module Rack
5
3
  class Joint
6
4
  class BadRedirectError < StandardError; end
7
5
 
8
6
  class RedirectInterface
9
- attr_reader :scheme, :request_scheme, :old_host, :old_path
7
+ attr_reader :scheme, :request_scheme, :request_query, :old_host, :old_path
10
8
  def initialize(request, old_host, old_path, &block)
11
9
  @status = 301
12
10
  @scheme = nil
11
+ @request_query = request.query_string
13
12
  @request_scheme = request.scheme
14
13
  @old_host = old_host
15
14
  @old_path = old_path || request.path_info
@@ -21,8 +20,8 @@ module Rack
21
20
  @scheme ||= request_scheme
22
21
  @new_host ||= old_host
23
22
  @new_path ||= old_path
24
- old_url = build_uri(request_scheme, old_host, old_path)
25
- new_location = build_uri(scheme, @new_host, @new_path)
23
+ old_url = UrlBuilder.new(request_scheme, request_query, old_host, old_path).build
24
+ new_location = UrlBuilder.new(scheme, request_query, @new_host, @new_path).build
26
25
  if old_url == new_location
27
26
  raise BadRedirectError.new('Redirect URL has been declared the same as current URL.')
28
27
  end
@@ -31,18 +30,6 @@ module Rack
31
30
 
32
31
  private
33
32
 
34
- # @param scheme [String] 'http' or 'https'
35
- # @param host [String] Host name
36
- # @param path [String] Path name
37
- # @return [URI]
38
- def build_uri(scheme, host, path)
39
- if scheme == 'https'
40
- URI::HTTPS.build({ scheme: scheme, host: host, path: path }).to_s
41
- else
42
- URI::HTTP.build({ scheme: scheme, host: host, path: path }).to_s
43
- end
44
- end
45
-
46
33
  # @param flag [Boolean]
47
34
  # @return [String] `http` or `https`
48
35
  def ssl(flag)
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+ require 'uri'
3
+
4
+ module Rack
5
+ class Joint
6
+ class UrlBuilder
7
+ attr_reader :scheme, :query, :host, :path
8
+ def initialize(scheme, request_query, host, path)
9
+ @scheme = scheme
10
+ @query = request_query
11
+ @host = host
12
+ @path = path
13
+ end
14
+
15
+ # @return [URI] URL with SSL or non-SSL
16
+ def build
17
+ if scheme == 'https'
18
+ https_url_builder
19
+ else
20
+ http_url_builder
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ # @return [URI]
27
+ def https_url_builder
28
+ # When query parameters isn't added to request URL,
29
+ # returns empty String object with `Rack::Request::Helper#query_string`.
30
+ if query.empty?
31
+ URI::HTTPS.build({ host: host, path: path }).to_s
32
+ else
33
+ URI::HTTPS.build({ host: host, path: path, query: query }).to_s
34
+ end
35
+ end
36
+
37
+ # @return [URI]
38
+ def http_url_builder
39
+ # When query parameters isn't added to request URL,
40
+ # returns empty String object with `Rack::Request::Helper#query_string`.
41
+ if query.empty?
42
+ URI::HTTP.build({ host: host, path: path }).to_s
43
+ else
44
+ URI::HTTP.build({ host: host, path: path, query: query }).to_s
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Joint
3
- VERSION = "0.3.3"
3
+ VERSION = "0.3.5"
4
4
  end
5
5
  end
data/lib/rack/joint.rb CHANGED
@@ -2,6 +2,7 @@ require "rack"
2
2
  require "rack/joint/context"
3
3
  require "rack/joint/redirect"
4
4
  require "rack/joint/redirect_interface"
5
+ require "rack/joint/url_builder"
5
6
  require "rack/joint/version"
6
7
 
7
8
  module Rack
@@ -27,7 +28,7 @@ module Rack
27
28
 
28
29
  private
29
30
 
30
- # @param mapping [Array] URI mappings for redirecting.
31
+ # @param mappings [Array] URI mappings for redirecting.
31
32
  # @param host [String] Requested hostname(env).
32
33
  # @return [Array] Return URL mapped responses.
33
34
  def valid_mapping(mappings, host)
data/rack-joint.gemspec CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_dependency "rack"
23
+ spec.add_dependency "rack", "~> 3.0"
24
24
  spec.add_development_dependency "bundler", ">= 1.17"
25
- spec.add_development_dependency "rake", "~> 12.0"
25
+ spec.add_development_dependency "rake", "~> 13.0"
26
26
  spec.add_development_dependency "minitest", "~> 5.0"
27
27
  spec.add_development_dependency "rack-test"
28
28
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-joint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akito Kasai
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-19 00:00:00.000000000 Z
11
+ date: 2023-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '12.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '12.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -88,8 +88,8 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - ".github/workflows/ruby.yml"
91
92
  - ".gitignore"
92
- - ".travis.yml"
93
93
  - CHANGELOG.md
94
94
  - Gemfile
95
95
  - LICENSE.txt
@@ -102,13 +102,14 @@ files:
102
102
  - lib/rack/joint/context.rb
103
103
  - lib/rack/joint/redirect.rb
104
104
  - lib/rack/joint/redirect_interface.rb
105
+ - lib/rack/joint/url_builder.rb
105
106
  - lib/rack/joint/version.rb
106
107
  - rack-joint.gemspec
107
108
  homepage: https://github.com/akito19/rack-joint
108
109
  licenses:
109
110
  - MIT
110
111
  metadata: {}
111
- post_install_message:
112
+ post_install_message:
112
113
  rdoc_options: []
113
114
  require_paths:
114
115
  - lib
@@ -123,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  - !ruby/object:Gem::Version
124
125
  version: '0'
125
126
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.7.6
128
- signing_key:
127
+ rubygems_version: 3.3.7
128
+ signing_key:
129
129
  specification_version: 4
130
130
  summary: A rack middleware for redirecting.
131
131
  test_files: []
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.4
5
- - 2.5.1
6
- - 2.6.0
7
- before_install: gem install bundler
8
- script: bundle exec rake test