redirect-rails 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6690ed059ca2cea75e6303e9a9a0901448a1d65950d8fd2f4cf2bd9fba22217
4
- data.tar.gz: a9f26f09c3700e70522ab9d9032cbc76bbe02738e7ff8575d26732c0d7311446
3
+ metadata.gz: 83fbf537ec5bec148fc7fb605932cc4514ce7cc2f66e7bedc1ab23be6fd2d350
4
+ data.tar.gz: 55ccabcdf89064ee821d8ec0a00b9a7674d55294496c03b8b6433f382c276d72
5
5
  SHA512:
6
- metadata.gz: aa5a76a662e15d69a78a1774714a7aa109c8aa298f09d677646fb1b5f323801f6809809f674a296e5664a77e9cbb8c3ed53d57af49b05425c2aeebd892b155b0
7
- data.tar.gz: 06f16613d08a5e0e0232d7d99f4e9768f39dbf07d9a5e28277daa4cdbf4eda992b37035f1d166dfac99de6f862f08535696ada3b9e3b78de4152bc4dd9a2dc94
6
+ metadata.gz: c99ff1039100db235d2202d2ae4c4f85414099fc7f25d0b4128f1fcbe9a68c4763aeaa7104ccfaf0bf5130069235325a322e8f85ff655725f4c26b4a99e3392b
7
+ data.tar.gz: bfec9aac126a0c2e37fb2aaf94eed91c45f0eb47715f897afb077e3c57359882601963e14e80c8e00422089216dc264be97c83f274091cef27aadb28906b7497
@@ -8,13 +8,15 @@ module Redirect
8
8
 
9
9
  def call(env)
10
10
  @request = Rack::Request.new(env)
11
- if url = redirect_url(@request.path)
11
+ if url = redirect_url(@request.path) || url = redirect_host(@request.host)
12
12
  redirect_to(url)
13
13
  else
14
14
  @app.call(env)
15
15
  end
16
16
  end
17
17
 
18
+ private
19
+
18
20
  def redirect_url(request_path)
19
21
  return unless Redirect::Rails.paths
20
22
 
@@ -23,6 +25,14 @@ module Redirect
23
25
  end.first
24
26
  end
25
27
 
28
+ def redirect_host(request_host)
29
+ return unless Redirect::Rails.hosts
30
+
31
+ Redirect::Rails.hosts.map do |host, redirect_url|
32
+ return ERB.new(redirect_url).result(binding) if Regexp.new(host).match(request_url)
33
+ end.first
34
+ end
35
+
26
36
  def redirect_to(uri)
27
37
  headers = { "Location": uri,
28
38
  "Content-Type": @request["Content-Type"],
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Redirect
4
4
  module Rails
5
- VERSION = "0.2.2"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -24,6 +24,10 @@ module Redirect
24
24
  YAML.safe_load(File.read(yaml_name))['paths']
25
25
  end
26
26
 
27
+ def hosts
28
+ YAML.safe_load(File.read(yaml_name))['hosts']
29
+ end
30
+
27
31
  def original_yaml_name
28
32
  "#{Redirect::Rails.root}/config/redirect.yml"
29
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redirect-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-10 00:00:00.000000000 Z
11
+ date: 2024-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails