rack-joint 0.3.0 → 0.3.1

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: f3059643a9228fad6f23fa1f0a6851023c1612c5bd8fbbde57fe0f584f600ca9
4
- data.tar.gz: '05907c6390bfb966cd2a517c0a2e247f2b51a449aaee09da4e2b27f2368fd6b2'
3
+ metadata.gz: e075ae01a8c1e321982092d1cd42f73839fe03b5512e8df0db28800ca0070afa
4
+ data.tar.gz: 5235f650cbe432e151ccde280863a0db2b713a568d8740ae9099ec4ac9a13959
5
5
  SHA512:
6
- metadata.gz: 6cdb06e0d4b1e06182f8a69d6d78907b19cd39f5ac925c5b9c14ec642a123f8336b31af5adc974715b3fe6b102b4f3650bc226066774a8799fd7d16f75cc60a1
7
- data.tar.gz: 6d2222cb89b23d1e014bb74dd42c07f2cc55c569f18342c8ac647fb3669c0a9080499a4991ed66ebd415d386bbecdbc7b08fd8f6a1a97737e2e39a918ea2fb8b
6
+ metadata.gz: a9067790ffb450986985cf77c9e1f9e5ba0495c513d4027a68d3fb376d12daae0705e03de9d0d1306799c05867ed5c3237f7c42f052942b571a4b07858efaffc
7
+ data.tar.gz: 58370cd859b9c191c2f789f21c90ffd4f59a73d2fc2bb907e93cb3c5d6e98ba485097d2381663cee7cfec05c75d275560d1d5108254e3ffddd8764f28146f4d4
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ### 0.3.1 (2018-12-05)
6
+ * Enable to redirect with an only host replaced. [#9](https://github.com/akito19/rack-joint/pull/9)
7
+
5
8
  ### 0.3.0 (2018-09-01)
6
9
  * Determine scheme in response to requests. [#7](https://github.com/akito19/rack-joint/pull/7)
7
10
 
data/README.md CHANGED
@@ -62,6 +62,16 @@ use Rack::Joint do
62
62
  new_host 'example.org'
63
63
  end
64
64
  end
65
+
66
+ # Following description allows you to redirect to URL you set with only host replaced.
67
+ #
68
+ # e.g. When accessing 'http://example.io/foo/bar/baz',
69
+ # redirect to `http://example.org/foob/bar/baz` with 301.
70
+ host 'example.io' do
71
+ redirect do
72
+ new_host 'example.org'
73
+ end
74
+ end
65
75
  end
66
76
 
67
77
  run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['Hello World!']] }
@@ -71,12 +81,12 @@ You can use following resources with block.
71
81
 
72
82
  | Resource | Type | Description |
73
83
  | :------- | :--- | :---------- |
74
- | `host` | String | Host name. |
75
- | `redirect` | String | Path name. |
76
- | `ssl` | Boolean | Whether to enable SSL. If the option isn't set, the scheme of `Location` header is determined in response to GET request. |
77
- | `new_host` | String | A new host name redirects to. |
78
- | `to` | String | A new path name redirects to. |
79
- | `status` | Integer | Status when redirecting. You can use `301`, `302`, `303`, `307`, `308`; which is `301` to default. |
84
+ | `host` | `string` | Required. Host name. |
85
+ | `redirect` | `string` | Path name. If you give nothing with this option, Rack::Joint will replace only host name. |
86
+ | `ssl` | `boolean` | Whether to enable SSL. If the option isn't set, the scheme of `Location` header is determined in response to GET request. |
87
+ | `new_host` | `string` | A new host name redirects to. |
88
+ | `to` | `string` | A new path name redirects to. |
89
+ | `status` | `integer` | Status when redirecting. You can use `301`, `302`, `303`, `307`, `308`; which is `301` to default. |
80
90
 
81
91
  ## Development
82
92
 
@@ -13,7 +13,7 @@ module Rack
13
13
  # @param old_path [String] Path set as argument in `config.ru`.
14
14
  # @param &block [block] Given block with `redirect`.
15
15
  # @return [Array] Return Array consisted of block under `redirect`.
16
- def redirect(old_path, &block)
16
+ def redirect(old_path = nil, &block)
17
17
  responses << RedirectInterface.new(request, old_host, old_path, &block).apply!
18
18
  end
19
19
  end
@@ -6,14 +6,13 @@ module Rack
6
6
  class BadRedirectError < StandardError; end
7
7
 
8
8
  class RedirectInterface
9
- attr_reader :scheme, :request_scheme, :old_host, :old_path, :old_url
9
+ attr_reader :scheme, :request_scheme, :old_host, :old_path
10
10
  def initialize(request, old_host, old_path, &block)
11
11
  @status = 301
12
12
  @scheme = nil
13
13
  @request_scheme = request.scheme
14
14
  @old_host = old_host
15
- @old_path = old_path
16
- @old_url = build_uri(request_scheme, old_host, old_path)
15
+ @old_path = old_path || request.path_info
17
16
  instance_exec(&block)
18
17
  end
19
18
 
@@ -22,6 +21,7 @@ module Rack
22
21
  @scheme ||= request_scheme
23
22
  @new_host ||= old_host
24
23
  @new_path ||= old_path
24
+ old_url = build_uri(request_scheme, old_host, old_path)
25
25
  new_location = build_uri(scheme, @new_host, @new_path)
26
26
  if old_url == new_location
27
27
  raise BadRedirectError.new('Redirect URL has been declared the same as current URL.')
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Joint
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-joint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akito Kasai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-01 00:00:00.000000000 Z
11
+ date: 2018-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack