tarquinn 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +85 -0
  3. data/.gitignore +10 -0
  4. data/.rubocop.yml +29 -0
  5. data/.rubocop_todo.yml +13 -0
  6. data/Dockerfile +21 -0
  7. data/Gemfile +16 -2
  8. data/README.md +16 -0
  9. data/Rakefile +8 -3
  10. data/config/check_specs.yml +3 -0
  11. data/config/rubycritc.rb +12 -0
  12. data/config/yardstick.rb +13 -0
  13. data/config/yardstick.yml +33 -0
  14. data/docker-compose.yml +23 -0
  15. data/lib/tarquinn/class_methods.rb +43 -12
  16. data/lib/tarquinn/condition/action_checker.rb +24 -7
  17. data/lib/tarquinn/condition/method_caller.rb +25 -8
  18. data/lib/tarquinn/condition/proc_runner.rb +18 -7
  19. data/lib/tarquinn/condition.rb +57 -4
  20. data/lib/tarquinn/controller.rb +56 -13
  21. data/lib/tarquinn/redirection_config.rb +92 -0
  22. data/lib/tarquinn/redirection_handler.rb +97 -0
  23. data/lib/tarquinn/request_handler.rb +61 -0
  24. data/lib/tarquinn/request_handler_builder.rb +84 -0
  25. data/lib/tarquinn/version.rb +3 -1
  26. data/lib/tarquinn.rb +74 -8
  27. data/spec/dummy/Rakefile +8 -0
  28. data/spec/dummy/app/assets/images/.keep +0 -0
  29. data/spec/dummy/app/assets/stylesheets/application.css +1 -0
  30. data/spec/dummy/app/channels/application_cable/channel.rb +6 -0
  31. data/spec/dummy/app/channels/application_cable/connection.rb +6 -0
  32. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  33. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  34. data/spec/dummy/app/controllers/tarquinn/dummy_controller.rb +43 -0
  35. data/spec/dummy/app/controllers/tarquinn/dummy_route_controller.rb +37 -0
  36. data/spec/dummy/app/helpers/application_helper.rb +4 -0
  37. data/spec/dummy/app/jobs/application_job.rb +9 -0
  38. data/spec/dummy/app/mailers/application_mailer.rb +6 -0
  39. data/spec/dummy/app/models/application_record.rb +5 -0
  40. data/spec/dummy/app/models/concerns/.keep +0 -0
  41. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  42. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  43. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  44. data/spec/dummy/app/views/tarquinn/dummy_route/index.html +0 -0
  45. data/spec/dummy/app/views/tarquinn/dummy_route/new.html +0 -0
  46. data/spec/dummy/bin/rails +6 -0
  47. data/spec/dummy/bin/rake +6 -0
  48. data/spec/dummy/bin/setup +35 -0
  49. data/spec/dummy/config/application.rb +24 -0
  50. data/spec/dummy/config/boot.rb +7 -0
  51. data/spec/dummy/config/cable.yml +10 -0
  52. data/spec/dummy/config/database.yml +25 -0
  53. data/spec/dummy/config/environment.rb +7 -0
  54. data/spec/dummy/config/environments/development.rb +69 -0
  55. data/spec/dummy/config/environments/production.rb +89 -0
  56. data/spec/dummy/config/environments/test.rb +62 -0
  57. data/spec/dummy/config/initializers/content_security_policy.rb +26 -0
  58. data/spec/dummy/config/initializers/filter_parameter_logging.rb +10 -0
  59. data/spec/dummy/config/initializers/inflections.rb +17 -0
  60. data/spec/dummy/config/initializers/permissions_policy.rb +12 -0
  61. data/spec/dummy/config/locales/en.yml +33 -0
  62. data/spec/dummy/config/puma.rb +45 -0
  63. data/spec/dummy/config/routes.rb +8 -0
  64. data/spec/dummy/config/storage.yml +34 -0
  65. data/spec/dummy/config.ru +8 -0
  66. data/spec/dummy/db/schema.rb +16 -0
  67. data/spec/dummy/lib/assets/.keep +0 -0
  68. data/spec/dummy/log/.keep +0 -0
  69. data/spec/dummy/public/404.html +67 -0
  70. data/spec/dummy/public/422.html +67 -0
  71. data/spec/dummy/public/500.html +66 -0
  72. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  73. data/spec/dummy/public/apple-touch-icon.png +0 -0
  74. data/spec/dummy/public/favicon.ico +0 -0
  75. data/spec/dummy/storage/.keep +0 -0
  76. data/spec/dummy/tmp/.keep +0 -0
  77. data/spec/dummy/tmp/pids/.keep +0 -0
  78. data/spec/dummy/tmp/storage/.keep +0 -0
  79. data/spec/lib/tarquinn/condition/action_checker_spec.rb +4 -2
  80. data/spec/lib/tarquinn/condition/method_caller_spec.rb +5 -3
  81. data/spec/lib/tarquinn/condition/proc_runner_spec.rb +56 -4
  82. data/spec/lib/tarquinn/condition_spec.rb +53 -0
  83. data/spec/lib/tarquinn/controller_spec.rb +83 -10
  84. data/spec/lib/tarquinn/{config_spec.rb → redirection_config_spec.rb} +3 -1
  85. data/spec/lib/tarquinn/{handler_spec.rb → redirection_handler_spec.rb} +21 -3
  86. data/spec/lib/tarquinn/request_handler_builder_spec.rb +15 -0
  87. data/spec/lib/tarquinn/{engine_spec.rb → request_handler_spec.rb} +5 -3
  88. data/spec/lib/tarquinn_spec.rb +176 -13
  89. data/spec/spec_helper.rb +17 -7
  90. data/spec/support/shared_examples/config.rb +5 -4
  91. data/tarquinn.gemspec +10 -14
  92. data/tarquinn.jpg +0 -0
  93. metadata +83 -107
  94. data/Gemfile.lock +0 -58
  95. data/lib/tarquinn/builder.rb +0 -28
  96. data/lib/tarquinn/concern.rb +0 -17
  97. data/lib/tarquinn/config.rb +0 -39
  98. data/lib/tarquinn/engine.rb +0 -31
  99. data/lib/tarquinn/handler.rb +0 -49
  100. data/spec/lib/tarquinn/builder_spec.rb +0 -13
  101. data/spec/support/models/tarquinn/dummy_controller.rb +0 -43
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
4
 
3
- SimpleCov.profiles.define 'gem' do
5
+ SimpleCov.start do
4
6
  add_filter '/spec/'
5
7
  end
6
8
 
7
- SimpleCov.start 'gem'
8
-
9
9
  require 'tarquinn'
10
10
  require 'pry-nav'
11
11
 
12
- support_files = File.expand_path("spec/support/**/*.rb")
13
- Dir[support_files].each { |file| require file }
12
+ require 'active_record'
13
+ ActiveRecord::Base.establish_connection(
14
+ adapter: 'sqlite3', database: ':memory:'
15
+ )
16
+
17
+ require File.expand_path('spec/dummy/config/environment')
18
+ # require File.expand_path('spec/dummy/db/schema.rb')
19
+ require 'rspec/rails'
20
+ require 'active_support/railtie'
21
+
22
+ support_files = File.expand_path('spec/support/**/*.rb')
23
+ Dir[support_files].each { |file| require file }
14
24
 
15
25
  RSpec.configure do |config|
16
26
  config.treat_symbols_as_metadata_keys_with_true_values = true
@@ -20,6 +30,6 @@ RSpec.configure do |config|
20
30
 
21
31
  config.order = 'random'
22
32
 
23
- config.before do
24
- end
33
+ # config.before do
34
+ # end
25
35
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_examples 'a method that adds a redirection rule' do |expected_class|
2
4
  it_behaves_like 'a method that adds a rule', :redirection, expected_class
3
5
  end
@@ -11,18 +13,17 @@ shared_examples 'a method that adds a rule' do |rule, expected_class|
11
13
  it do
12
14
  expect do
13
15
  call_method
14
- end.to change { subject.public_send("#{rule}_blocks" ) }
16
+ end.to change(subject, "#{rule}_blocks")
15
17
  end
16
18
 
17
19
  it do
18
20
  call_method
19
- expect(subject.public_send("#{rule}_blocks" ).last).to be_a(expected_class)
21
+ expect(subject.public_send("#{rule}_blocks").last).to be_a(expected_class)
20
22
  end
21
23
 
22
24
  it do
23
25
  expect do
24
26
  call_method
25
- end.not_to change { subject.public_send("#{reverse_rule}_blocks" ) }
27
+ end.not_to change(subject, "#{reverse_rule}_blocks")
26
28
  end
27
29
  end
28
-
data/tarquinn.gemspec CHANGED
@@ -1,28 +1,24 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'tarquinn/version'
5
6
 
6
7
  Gem::Specification.new do |gem|
7
8
  gem.name = 'tarquinn'
8
9
  gem.version = Tarquinn::VERSION
9
- gem.authors = %w(DarthJee)
10
- gem.email = %w(darthjee@gmail.com)
10
+ gem.authors = %w[DarthJee]
11
+ gem.email = %w[darthjee@gmail.com]
11
12
  gem.homepage = 'https://github.com/darthje/tarquinn'
12
13
  gem.description = 'Gem for easy redirection controll'
13
14
  gem.summary = gem.description
15
+ gem.required_ruby_version = '>= 3.3.1'
14
16
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
18
- gem.require_paths = ["lib"]
17
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ gem.require_paths = ['lib']
19
20
 
20
21
  gem.add_runtime_dependency 'activesupport'
21
22
 
22
- gem.add_development_dependency "bundler", "~> 1.6"
23
- gem.add_development_dependency "rake"
24
- gem.add_development_dependency "rspec", "~> 2.14"
25
- gem.add_development_dependency 'simplecov'
26
- gem.add_development_dependency 'pry'
27
- gem.add_development_dependency 'pry-nav'
23
+ gem.metadata['rubygems_mfa_required'] = 'true'
28
24
  end
data/tarquinn.jpg ADDED
Binary file
metadata CHANGED
@@ -1,111 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarquinn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarthJee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-04 00:00:00.000000000 Z
11
+ date: 2024-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '1.6'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: '1.6'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '2.14'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: '2.14'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: pry-nav
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - '>='
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - '>='
24
+ - - ">="
109
25
  - !ruby/object:Gem::Version
110
26
  version: '0'
111
27
  description: Gem for easy redirection controll
@@ -115,59 +31,119 @@ executables: []
115
31
  extensions: []
116
32
  extra_rdoc_files: []
117
33
  files:
118
- - .gitignore
119
- - .rspec
34
+ - ".circleci/config.yml"
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".rubocop.yml"
38
+ - ".rubocop_todo.yml"
39
+ - Dockerfile
120
40
  - Gemfile
121
- - Gemfile.lock
122
41
  - LICENSE
123
42
  - README.md
124
43
  - Rakefile
44
+ - config/check_specs.yml
45
+ - config/rubycritc.rb
46
+ - config/yardstick.rb
47
+ - config/yardstick.yml
48
+ - docker-compose.yml
125
49
  - lib/tarquinn.rb
126
- - lib/tarquinn/builder.rb
127
50
  - lib/tarquinn/class_methods.rb
128
- - lib/tarquinn/concern.rb
129
51
  - lib/tarquinn/condition.rb
130
52
  - lib/tarquinn/condition/action_checker.rb
131
53
  - lib/tarquinn/condition/method_caller.rb
132
54
  - lib/tarquinn/condition/proc_runner.rb
133
- - lib/tarquinn/config.rb
134
55
  - lib/tarquinn/controller.rb
135
- - lib/tarquinn/engine.rb
136
- - lib/tarquinn/handler.rb
56
+ - lib/tarquinn/redirection_config.rb
57
+ - lib/tarquinn/redirection_handler.rb
58
+ - lib/tarquinn/request_handler.rb
59
+ - lib/tarquinn/request_handler_builder.rb
137
60
  - lib/tarquinn/version.rb
138
- - spec/lib/tarquinn/builder_spec.rb
61
+ - spec/dummy/Rakefile
62
+ - spec/dummy/app/assets/images/.keep
63
+ - spec/dummy/app/assets/stylesheets/application.css
64
+ - spec/dummy/app/channels/application_cable/channel.rb
65
+ - spec/dummy/app/channels/application_cable/connection.rb
66
+ - spec/dummy/app/controllers/application_controller.rb
67
+ - spec/dummy/app/controllers/concerns/.keep
68
+ - spec/dummy/app/controllers/tarquinn/dummy_controller.rb
69
+ - spec/dummy/app/controllers/tarquinn/dummy_route_controller.rb
70
+ - spec/dummy/app/helpers/application_helper.rb
71
+ - spec/dummy/app/jobs/application_job.rb
72
+ - spec/dummy/app/mailers/application_mailer.rb
73
+ - spec/dummy/app/models/application_record.rb
74
+ - spec/dummy/app/models/concerns/.keep
75
+ - spec/dummy/app/views/layouts/application.html.erb
76
+ - spec/dummy/app/views/layouts/mailer.html.erb
77
+ - spec/dummy/app/views/layouts/mailer.text.erb
78
+ - spec/dummy/app/views/tarquinn/dummy_route/index.html
79
+ - spec/dummy/app/views/tarquinn/dummy_route/new.html
80
+ - spec/dummy/bin/rails
81
+ - spec/dummy/bin/rake
82
+ - spec/dummy/bin/setup
83
+ - spec/dummy/config.ru
84
+ - spec/dummy/config/application.rb
85
+ - spec/dummy/config/boot.rb
86
+ - spec/dummy/config/cable.yml
87
+ - spec/dummy/config/database.yml
88
+ - spec/dummy/config/environment.rb
89
+ - spec/dummy/config/environments/development.rb
90
+ - spec/dummy/config/environments/production.rb
91
+ - spec/dummy/config/environments/test.rb
92
+ - spec/dummy/config/initializers/content_security_policy.rb
93
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
94
+ - spec/dummy/config/initializers/inflections.rb
95
+ - spec/dummy/config/initializers/permissions_policy.rb
96
+ - spec/dummy/config/locales/en.yml
97
+ - spec/dummy/config/puma.rb
98
+ - spec/dummy/config/routes.rb
99
+ - spec/dummy/config/storage.yml
100
+ - spec/dummy/db/schema.rb
101
+ - spec/dummy/lib/assets/.keep
102
+ - spec/dummy/log/.keep
103
+ - spec/dummy/public/404.html
104
+ - spec/dummy/public/422.html
105
+ - spec/dummy/public/500.html
106
+ - spec/dummy/public/apple-touch-icon-precomposed.png
107
+ - spec/dummy/public/apple-touch-icon.png
108
+ - spec/dummy/public/favicon.ico
109
+ - spec/dummy/storage/.keep
110
+ - spec/dummy/tmp/.keep
111
+ - spec/dummy/tmp/pids/.keep
112
+ - spec/dummy/tmp/storage/.keep
139
113
  - spec/lib/tarquinn/condition/action_checker_spec.rb
140
114
  - spec/lib/tarquinn/condition/method_caller_spec.rb
141
115
  - spec/lib/tarquinn/condition/proc_runner_spec.rb
142
- - spec/lib/tarquinn/config_spec.rb
116
+ - spec/lib/tarquinn/condition_spec.rb
143
117
  - spec/lib/tarquinn/controller_spec.rb
144
- - spec/lib/tarquinn/engine_spec.rb
145
- - spec/lib/tarquinn/handler_spec.rb
118
+ - spec/lib/tarquinn/redirection_config_spec.rb
119
+ - spec/lib/tarquinn/redirection_handler_spec.rb
120
+ - spec/lib/tarquinn/request_handler_builder_spec.rb
121
+ - spec/lib/tarquinn/request_handler_spec.rb
146
122
  - spec/lib/tarquinn_spec.rb
147
123
  - spec/spec_helper.rb
148
- - spec/support/models/tarquinn/dummy_controller.rb
149
124
  - spec/support/shared_examples/config.rb
150
125
  - tarquinn.gemspec
126
+ - tarquinn.jpg
151
127
  homepage: https://github.com/darthje/tarquinn
152
128
  licenses: []
153
- metadata: {}
129
+ metadata:
130
+ rubygems_mfa_required: 'true'
154
131
  post_install_message:
155
132
  rdoc_options: []
156
133
  require_paths:
157
134
  - lib
158
135
  required_ruby_version: !ruby/object:Gem::Requirement
159
136
  requirements:
160
- - - '>='
137
+ - - ">="
161
138
  - !ruby/object:Gem::Version
162
- version: '0'
139
+ version: 3.3.1
163
140
  required_rubygems_version: !ruby/object:Gem::Requirement
164
141
  requirements:
165
- - - '>='
142
+ - - ">="
166
143
  - !ruby/object:Gem::Version
167
144
  version: '0'
168
145
  requirements: []
169
- rubyforge_project:
170
- rubygems_version: 2.4.6
146
+ rubygems_version: 3.5.9
171
147
  signing_key:
172
148
  specification_version: 4
173
149
  summary: Gem for easy redirection controll
data/Gemfile.lock DELETED
@@ -1,58 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- tarquinn (0.1.0)
5
- activesupport
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activesupport (4.2.3)
11
- i18n (~> 0.7)
12
- json (~> 1.7, >= 1.7.7)
13
- minitest (~> 5.1)
14
- thread_safe (~> 0.3, >= 0.3.4)
15
- tzinfo (~> 1.1)
16
- coderay (1.1.0)
17
- diff-lcs (1.2.5)
18
- docile (1.1.5)
19
- i18n (0.7.0)
20
- json (1.8.3)
21
- method_source (0.8.2)
22
- minitest (5.8.0)
23
- pry (0.10.1)
24
- coderay (~> 1.1.0)
25
- method_source (~> 0.8.1)
26
- slop (~> 3.4)
27
- pry-nav (0.2.4)
28
- pry (>= 0.9.10, < 0.11.0)
29
- rake (10.4.2)
30
- rspec (2.99.0)
31
- rspec-core (~> 2.99.0)
32
- rspec-expectations (~> 2.99.0)
33
- rspec-mocks (~> 2.99.0)
34
- rspec-core (2.99.2)
35
- rspec-expectations (2.99.2)
36
- diff-lcs (>= 1.1.3, < 2.0)
37
- rspec-mocks (2.99.4)
38
- simplecov (0.10.0)
39
- docile (~> 1.1.0)
40
- json (~> 1.8)
41
- simplecov-html (~> 0.10.0)
42
- simplecov-html (0.10.0)
43
- slop (3.6.0)
44
- thread_safe (0.3.5)
45
- tzinfo (1.2.2)
46
- thread_safe (~> 0.1)
47
-
48
- PLATFORMS
49
- ruby
50
-
51
- DEPENDENCIES
52
- bundler (~> 1.6)
53
- pry
54
- pry-nav
55
- rake
56
- rspec (~> 2.14)
57
- simplecov
58
- tarquinn!
@@ -1,28 +0,0 @@
1
- class Tarquinn::Builder
2
- def add_skip_action(redirection, *actions)
3
- config_for(redirection).add_skip_action(*actions)
4
- end
5
-
6
- def add_redirection_config(redirection, *methods, block)
7
- config_for(redirection).add_redirection_rules(*methods, &block)
8
- end
9
-
10
- def add_skip_config(redirection, *methods, block)
11
- config_for(redirection).add_skip_rules(*methods, &block)
12
- end
13
-
14
- def build(controller)
15
- controller = Tarquinn::Controller.new(controller)
16
- Tarquinn::Engine.new(configs, controller)
17
- end
18
-
19
- private
20
-
21
- def config_for(redirection)
22
- configs[redirection.to_sym] ||= Tarquinn::Config.new(redirection)
23
- end
24
-
25
- def configs
26
- @configs ||= {}
27
- end
28
- end
@@ -1,17 +0,0 @@
1
- module Tarquinn
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- before_action :perform_redirection
6
- end
7
-
8
- private
9
-
10
- def redirector_engine
11
- self.class.redirector_builder.build(self)
12
- end
13
-
14
- def perform_redirection
15
- redirector_engine.perform_redirect
16
- end
17
- end
@@ -1,39 +0,0 @@
1
- class Tarquinn::Config
2
- attr_accessor :redirect
3
-
4
- def initialize(redirect)
5
- @redirect = redirect
6
- end
7
-
8
- def add_skip_action(*routes)
9
- skip_blocks << block_routes(routes)
10
- end
11
-
12
- def add_redirection_rules(*methods, &block)
13
- redirection_blocks << block_methods(methods)
14
- redirection_blocks << Tarquinn::Condition::ProcRunner.new(&block) if block_given?
15
- end
16
-
17
- def add_skip_rules(*methods, &block)
18
- skip_blocks << block_methods(methods)
19
- skip_blocks << Tarquinn::Condition::ProcRunner.new(&block) if block_given?
20
- end
21
-
22
- def redirection_blocks
23
- @blocks ||= []
24
- end
25
-
26
- def skip_blocks
27
- @skip_blocks ||= []
28
- end
29
-
30
- private
31
-
32
- def block_methods(methods)
33
- Tarquinn::Condition::MethodCaller.new(methods)
34
- end
35
-
36
- def block_routes(routes)
37
- Tarquinn::Condition::ActionChecker.new(routes)
38
- end
39
- end
@@ -1,31 +0,0 @@
1
- class Tarquinn::Engine
2
- attr_reader :configs, :controller
3
-
4
- def initialize(configs, controller)
5
- @configs = configs
6
- @controller = controller
7
- end
8
-
9
- def perform_redirect
10
- return unless perform_redirect?
11
- handler_redirector.redirect
12
- end
13
-
14
- private
15
-
16
- def perform_redirect?
17
- handler_redirector.present?
18
- end
19
-
20
- def handler_redirector
21
- @handler_redirector ||= handlers.find { |h| h.perform_redirect? }
22
- end
23
-
24
- def handlers
25
- @handlers ||= build_handlers
26
- end
27
-
28
- def build_handlers
29
- configs.map { |_,c| Tarquinn::Handler.new(c, controller) }
30
- end
31
- end
@@ -1,49 +0,0 @@
1
- class Tarquinn::Handler
2
- attr_accessor :config, :controller
3
-
4
- delegate :redirection_blocks, :skip_blocks, to: :config
5
-
6
- def initialize(config, controller)
7
- @config = config
8
- @controller = controller
9
- end
10
-
11
- def perform_redirect?
12
- return @perform_redirect unless @perform_redirect.nil?
13
- @perform_redirect = is_redirect?
14
- end
15
-
16
- def redirect
17
- controller.call(:redirect_to, redirect_path)
18
- end
19
-
20
- private
21
-
22
- def redirect_method
23
- config.redirect
24
- end
25
-
26
- def redirect_path
27
- return redirect_method unless controller.has_method?(redirect_method)
28
- controller.call redirect_method
29
- end
30
-
31
- def is_redirect?
32
- return false if blocks_skip_redirect?
33
- blocks_require_redirect?
34
- end
35
-
36
- def blocks_skip_redirect?
37
- check_blocks(skip_blocks)
38
- end
39
-
40
- def blocks_require_redirect?
41
- check_blocks(redirection_blocks)
42
- end
43
-
44
- def check_blocks(blocks)
45
- blocks.any? do |block|
46
- block.check?(controller)
47
- end
48
- end
49
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Tarquinn::Builder do
4
- describe '#build' do
5
- let(:controller) do
6
- double('controller')
7
- end
8
-
9
- it do
10
- expect(subject.build(controller)).to be_a(Tarquinn::Engine)
11
- end
12
- end
13
- end
@@ -1,43 +0,0 @@
1
- class Tarquinn::DummyController
2
- def self.before_action(_)
3
- end
4
-
5
- include Tarquinn
6
-
7
- skip_redirection :redirection_path, :route_method
8
- redirection_rule :redirection_path, :should_redirect?
9
- skip_redirection_rule :redirection_path, :should_skip_redirect?
10
-
11
- def parse_request
12
- perform_redirection
13
- end
14
-
15
- private
16
-
17
- def params
18
- { action: 'show' }
19
- end
20
-
21
- def true
22
- true
23
- end
24
-
25
- def false
26
- false
27
- end
28
-
29
- def redirection_path
30
- '/path'
31
- end
32
-
33
- def redirect_to(_)
34
- end
35
-
36
- def should_redirect?
37
- true
38
- end
39
-
40
- def should_skip_redirect?
41
- false
42
- end
43
- end