redirect-rails 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f46377411074f4d5f0324f7bff7da2916112df9993b508d81955803b2c940716
4
- data.tar.gz: 31c05112cde8119377775e03e71215111c95392969c83f9cc2e70e9b2e34a047
3
+ metadata.gz: 83fbf537ec5bec148fc7fb605932cc4514ce7cc2f66e7bedc1ab23be6fd2d350
4
+ data.tar.gz: 55ccabcdf89064ee821d8ec0a00b9a7674d55294496c03b8b6433f382c276d72
5
5
  SHA512:
6
- metadata.gz: 23cca88b54bc5c1af86553e0ec161cd7d8a2d53c97132152d6865dff418b1967fd64956cf9f7dcc1b87d2f526219414d71c7642b379137e92e5f86cb8ef2e249
7
- data.tar.gz: 3245137b076b61c97321d3ce20383196ae2c51794d352a4c52eb9fe0c167c3dc4c676bf6e560a45a15b498fbfb26f274fd1e62cb731dbec62dc2c75331571c2f
6
+ metadata.gz: c99ff1039100db235d2202d2ae4c4f85414099fc7f25d0b4128f1fcbe9a68c4763aeaa7104ccfaf0bf5130069235325a322e8f85ff655725f4c26b4a99e3392b
7
+ data.tar.gz: bfec9aac126a0c2e37fb2aaf94eed91c45f0eb47715f897afb077e3c57359882601963e14e80c8e00422089216dc264be97c83f274091cef27aadb28906b7497
@@ -8,19 +8,29 @@ module Redirect
8
8
 
9
9
  def call(env)
10
10
  @request = Rack::Request.new(env)
11
- if response = match?(@request.path)
12
- response
11
+ if url = redirect_url(@request.path) || url = redirect_host(@request.host)
12
+ redirect_to(url)
13
13
  else
14
14
  @app.call(env)
15
15
  end
16
16
  end
17
17
 
18
- def match?(request_path)
18
+ private
19
+
20
+ def redirect_url(request_path)
19
21
  return unless Redirect::Rails.paths
20
22
 
21
23
  Redirect::Rails.paths.map do |path, redirect_path|
22
- return redirect_to(ERB.new(redirect_path).result(binding)) if Regexp.new(path).match(request_path)
23
- end
24
+ return ERB.new(redirect_path).result(binding) if Regexp.new(path).match(request_path)
25
+ end.first
26
+ end
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
24
34
  end
25
35
 
26
36
  def redirect_to(uri)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Redirect
4
4
  module Rails
5
- VERSION = "0.2.1"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -21,7 +21,11 @@ module Redirect
21
21
  end
22
22
 
23
23
  def paths
24
- YAML.load(ERB.new(File.read(yaml_name)).result)['paths']
24
+ YAML.safe_load(File.read(yaml_name))['paths']
25
+ end
26
+
27
+ def hosts
28
+ YAML.safe_load(File.read(yaml_name))['hosts']
25
29
  end
26
30
 
27
31
  def original_yaml_name
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.1
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