tarquinn 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +85 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +29 -0
- data/.rubocop_todo.yml +13 -0
- data/Dockerfile +21 -0
- data/Gemfile +16 -2
- data/README.md +16 -0
- data/Rakefile +8 -3
- data/config/check_specs.yml +3 -0
- data/config/rubycritc.rb +12 -0
- data/config/yardstick.rb +13 -0
- data/config/yardstick.yml +33 -0
- data/docker-compose.yml +23 -0
- data/lib/tarquinn/class_methods.rb +43 -12
- data/lib/tarquinn/condition/action_checker.rb +24 -7
- data/lib/tarquinn/condition/method_caller.rb +25 -8
- data/lib/tarquinn/condition/proc_runner.rb +18 -7
- data/lib/tarquinn/condition.rb +57 -4
- data/lib/tarquinn/controller.rb +56 -13
- data/lib/tarquinn/redirection_config.rb +92 -0
- data/lib/tarquinn/redirection_handler.rb +97 -0
- data/lib/tarquinn/request_handler.rb +61 -0
- data/lib/tarquinn/request_handler_builder.rb +84 -0
- data/lib/tarquinn/version.rb +3 -1
- data/lib/tarquinn.rb +74 -8
- data/spec/dummy/Rakefile +8 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +1 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +6 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/tarquinn/dummy_controller.rb +43 -0
- data/spec/dummy/app/controllers/tarquinn/dummy_route_controller.rb +37 -0
- data/spec/dummy/app/helpers/application_helper.rb +4 -0
- data/spec/dummy/app/jobs/application_job.rb +9 -0
- data/spec/dummy/app/mailers/application_mailer.rb +6 -0
- data/spec/dummy/app/models/application_record.rb +5 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/app/views/tarquinn/dummy_route/index.html +0 -0
- data/spec/dummy/app/views/tarquinn/dummy_route/new.html +0 -0
- data/spec/dummy/bin/rails +6 -0
- data/spec/dummy/bin/rake +6 -0
- data/spec/dummy/bin/setup +35 -0
- data/spec/dummy/config/application.rb +24 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +69 -0
- data/spec/dummy/config/environments/production.rb +89 -0
- data/spec/dummy/config/environments/test.rb +62 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +26 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +10 -0
- data/spec/dummy/config/initializers/inflections.rb +17 -0
- data/spec/dummy/config/initializers/permissions_policy.rb +12 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +45 -0
- data/spec/dummy/config/routes.rb +8 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +8 -0
- data/spec/dummy/db/schema.rb +16 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/storage/.keep +0 -0
- data/spec/dummy/tmp/.keep +0 -0
- data/spec/dummy/tmp/pids/.keep +0 -0
- data/spec/dummy/tmp/storage/.keep +0 -0
- data/spec/lib/tarquinn/condition/action_checker_spec.rb +4 -2
- data/spec/lib/tarquinn/condition/method_caller_spec.rb +5 -3
- data/spec/lib/tarquinn/condition/proc_runner_spec.rb +56 -4
- data/spec/lib/tarquinn/condition_spec.rb +53 -0
- data/spec/lib/tarquinn/controller_spec.rb +83 -10
- data/spec/lib/tarquinn/{config_spec.rb → redirection_config_spec.rb} +3 -1
- data/spec/lib/tarquinn/{handler_spec.rb → redirection_handler_spec.rb} +21 -3
- data/spec/lib/tarquinn/request_handler_builder_spec.rb +15 -0
- data/spec/lib/tarquinn/{engine_spec.rb → request_handler_spec.rb} +5 -3
- data/spec/lib/tarquinn_spec.rb +176 -13
- data/spec/spec_helper.rb +17 -7
- data/spec/support/shared_examples/config.rb +5 -4
- data/tarquinn.gemspec +10 -14
- data/tarquinn.jpg +0 -0
- metadata +83 -107
- data/Gemfile.lock +0 -58
- data/lib/tarquinn/builder.rb +0 -28
- data/lib/tarquinn/concern.rb +0 -17
- data/lib/tarquinn/config.rb +0 -39
- data/lib/tarquinn/engine.rb +0 -31
- data/lib/tarquinn/handler.rb +0 -49
- data/spec/lib/tarquinn/builder_spec.rb +0 -13
- data/spec/support/models/tarquinn/dummy_controller.rb +0 -43
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tarquinn
|
4
|
+
# @api private
|
5
|
+
#
|
6
|
+
# Redirection configuration
|
7
|
+
#
|
8
|
+
# @see Tarquinn::RequestHandler
|
9
|
+
class RedirectionConfig
|
10
|
+
attr_reader :redirect
|
11
|
+
|
12
|
+
# @param redirect [Symbol] redirection name and redirection method
|
13
|
+
def initialize(redirect)
|
14
|
+
@redirect = redirect
|
15
|
+
end
|
16
|
+
|
17
|
+
# Adds conditions to the rule
|
18
|
+
#
|
19
|
+
# The rule name defines which method will be called when checking the path of redirection
|
20
|
+
#
|
21
|
+
# @param methods [Array<Symbol>] Methods that tell that a redirection should be applied
|
22
|
+
# @param block [Proc] block that tells if a the redirection should be applied
|
23
|
+
#
|
24
|
+
# @return [Array<Tarquinn::Condition>] Current registered conditions
|
25
|
+
def add_redirection_rules(*methods, &block)
|
26
|
+
redirect_on method_caller(methods)
|
27
|
+
redirect_on proc_runner(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Add rule for skipping on some actions / routes
|
31
|
+
#
|
32
|
+
# @param actions [Array<Symbol>] actions / routes to be skipped by redirection rule
|
33
|
+
#
|
34
|
+
# @return [Array<Tarquinn::Condition>]
|
35
|
+
def add_skip_action(*actions)
|
36
|
+
skip action_checker(actions)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Attaches conditions to skip a redirection
|
40
|
+
#
|
41
|
+
# Methods and blocks are ran and if any returns true, the redirec is skipped
|
42
|
+
#
|
43
|
+
# @param methods [Array<Symbol>] Methods that tell that a redirection should be skipped
|
44
|
+
# @param block [Proc] block that tells if a the redirection should be skipped
|
45
|
+
#
|
46
|
+
# @return [Array] Current registered conditions
|
47
|
+
def add_skip_rules(*methods, &block)
|
48
|
+
skip method_caller(methods)
|
49
|
+
skip proc_runner(&block)
|
50
|
+
end
|
51
|
+
|
52
|
+
# All blocks that indicate a redirection
|
53
|
+
#
|
54
|
+
# @return [Array<Tarquinn::Condition>]
|
55
|
+
def redirection_blocks
|
56
|
+
@redirection_blocks ||= []
|
57
|
+
end
|
58
|
+
|
59
|
+
# All blocks that indicate a redirection should be skipped
|
60
|
+
#
|
61
|
+
# @return [Array<Tarquinn::Condition>]
|
62
|
+
def skip_blocks
|
63
|
+
@skip_blocks ||= []
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
delegate :method_caller, :action_checker, :proc_runner, to: Tarquinn::Condition
|
69
|
+
|
70
|
+
# @private
|
71
|
+
#
|
72
|
+
# Adds a condition to skip a redirection
|
73
|
+
#
|
74
|
+
# @return (see #skip_blocks)
|
75
|
+
def skip(condition)
|
76
|
+
return skip_blocks unless condition
|
77
|
+
|
78
|
+
skip_blocks << condition
|
79
|
+
end
|
80
|
+
|
81
|
+
# @private
|
82
|
+
#
|
83
|
+
# Adds a condition to a redirection
|
84
|
+
#
|
85
|
+
# @return (see #redirection_blocks)
|
86
|
+
def redirect_on(condition)
|
87
|
+
return redirection_blocks unless condition
|
88
|
+
|
89
|
+
redirection_blocks << condition
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tarquinn
|
4
|
+
# @api private
|
5
|
+
#
|
6
|
+
# Redirect config handler
|
7
|
+
#
|
8
|
+
# Checks if one redirection rule should or should not be applied
|
9
|
+
class RedirectionHandler
|
10
|
+
# @param config [Tarquinn::RedirectionConfig] redirection configuration
|
11
|
+
# @param controller [Tarquinn::Controller] controller interface
|
12
|
+
def initialize(config, controller)
|
13
|
+
@config = config
|
14
|
+
@controller = controller
|
15
|
+
end
|
16
|
+
|
17
|
+
# Checks if redirection should be performd
|
18
|
+
#
|
19
|
+
# @return [TrueClass] when redirection should be performed
|
20
|
+
# @return [FalseClass] when redirection should not be performed
|
21
|
+
def perform_redirect?
|
22
|
+
return perform_redirect if instance_variable_defined?(:@perform_redirect)
|
23
|
+
|
24
|
+
@perform_redirect = redirect?
|
25
|
+
end
|
26
|
+
|
27
|
+
# Performs redirction to a new route
|
28
|
+
#
|
29
|
+
# @return [String] redirection body
|
30
|
+
def redirect
|
31
|
+
controller.call(:redirect_to, redirect_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :config, :controller, :perform_redirect
|
37
|
+
|
38
|
+
delegate :redirection_blocks, :skip_blocks, to: :config
|
39
|
+
|
40
|
+
# Returns method in the controller that returns the redirection path
|
41
|
+
#
|
42
|
+
# @return [Symbol] method name
|
43
|
+
def redirect_method
|
44
|
+
config.redirect
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns the redirection path
|
48
|
+
#
|
49
|
+
# when redirection path method does not exist, then then
|
50
|
+
# the redirection name is used
|
51
|
+
#
|
52
|
+
# @return [String]
|
53
|
+
def redirect_path
|
54
|
+
return redirect_method unless controller.method?(redirect_method)
|
55
|
+
|
56
|
+
controller.call redirect_method
|
57
|
+
end
|
58
|
+
|
59
|
+
# Checks if a redirection should be performd
|
60
|
+
#
|
61
|
+
# @return [TrueClass]
|
62
|
+
# @return [FalseClass]
|
63
|
+
def redirect?
|
64
|
+
return false if blocks_skip_redirect?
|
65
|
+
|
66
|
+
blocks_require_redirect?
|
67
|
+
end
|
68
|
+
|
69
|
+
# Checks if redirection should be skipped
|
70
|
+
#
|
71
|
+
# @return [TrueClass]
|
72
|
+
# @return [FalseClass]
|
73
|
+
def blocks_skip_redirect?
|
74
|
+
check_blocks(skip_blocks)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Checks if redirection should be applied (not concerning the skip blocks)
|
78
|
+
#
|
79
|
+
# @return [TrueClass]
|
80
|
+
# @return [FalseClass]
|
81
|
+
def blocks_require_redirect?
|
82
|
+
return true if redirection_blocks.empty?
|
83
|
+
|
84
|
+
check_blocks(redirection_blocks)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Check if any condition returns positive
|
88
|
+
#
|
89
|
+
# @return [TrueClass]
|
90
|
+
# @return [FalseClass]
|
91
|
+
def check_blocks(blocks)
|
92
|
+
blocks.any? do |block|
|
93
|
+
block.check?(controller)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tarquinn
|
4
|
+
# @api private
|
5
|
+
#
|
6
|
+
# RequestHandler processing a request defining the flow
|
7
|
+
class RequestHandler
|
8
|
+
# @method configs
|
9
|
+
# @api private
|
10
|
+
#
|
11
|
+
# All redirect configs
|
12
|
+
#
|
13
|
+
# @return [Hash<Symbol,Tarquinn::RedirectionConfig>]
|
14
|
+
|
15
|
+
# @method controller
|
16
|
+
#
|
17
|
+
# Controller interface
|
18
|
+
#
|
19
|
+
# @return [Tarquinn::Controller]
|
20
|
+
|
21
|
+
# @param configs [Hash<Symbol,Tarquinn::RedirectionConfig>] All redirect configs
|
22
|
+
# @param controller [Tarquinn::Controller] Controller interface
|
23
|
+
def initialize(configs, controller)
|
24
|
+
@configs = configs
|
25
|
+
@controller = controller
|
26
|
+
end
|
27
|
+
|
28
|
+
# Performs redirection if enabled / needed
|
29
|
+
#
|
30
|
+
# The rules / configuratons are processed in order
|
31
|
+
# and if any is positive, it will be processed
|
32
|
+
#
|
33
|
+
# @return [NilClass] Nothing when no redirection is performed
|
34
|
+
# @return [String] The result of the redirection
|
35
|
+
def perform_redirect
|
36
|
+
return unless perform_redirect?
|
37
|
+
|
38
|
+
handler_redirector.redirect
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :configs, :controller
|
44
|
+
|
45
|
+
def perform_redirect?
|
46
|
+
handler_redirector.present?
|
47
|
+
end
|
48
|
+
|
49
|
+
def handler_redirector
|
50
|
+
@handler_redirector ||= handlers.find(&:perform_redirect?)
|
51
|
+
end
|
52
|
+
|
53
|
+
def handlers
|
54
|
+
@handlers ||= build_handlers
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_handlers
|
58
|
+
configs.values.map { |config| Tarquinn::RedirectionHandler.new(config, controller) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tarquinn
|
4
|
+
# @api private
|
5
|
+
#
|
6
|
+
# Redirections rules builder
|
7
|
+
#
|
8
|
+
# @see Tarquinn::RedirectionConfig
|
9
|
+
# @see Tarquinn::RequestHandler
|
10
|
+
# @see Tarquinn::Controller
|
11
|
+
class RequestHandlerBuilder
|
12
|
+
# Creates a redirection rule
|
13
|
+
#
|
14
|
+
# The rule name defines which method will be called when checking the path of redirection
|
15
|
+
#
|
16
|
+
# @param redirection [Symbol] Rule name and method with redirection path
|
17
|
+
# @param (see Tarquinn::RedirectionConfig#add_redirection_rules)
|
18
|
+
#
|
19
|
+
# @return (see Tarquinn::RedirectionConfig#add_redirection_rules)
|
20
|
+
def add_redirection_config(redirection, *methods, &block)
|
21
|
+
config_for(redirection).add_redirection_rules(*methods, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Attaches a condition to skip a redirection based on route (controller action)
|
25
|
+
#
|
26
|
+
# When any of the skip rules is met the redirection is skipped
|
27
|
+
#
|
28
|
+
# @param redirection [Symbol] Rule name to attach the skip condition
|
29
|
+
# @param (see Tarquinn::RedirectionConfig#add_skip_action)
|
30
|
+
#
|
31
|
+
# @return (see Tarquinn::RedirectionConfig#add_skip_action)
|
32
|
+
def add_skip_action(redirection, *actions)
|
33
|
+
config_for(redirection).add_skip_action(*actions)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Attaches conditions to skip a redirection
|
37
|
+
#
|
38
|
+
# Methods and blocks are ran and if any returns true, the redirec is skipped
|
39
|
+
#
|
40
|
+
# @param redirection [Symbol] Rule name to attach the skip condition
|
41
|
+
# @param (see Tarquinn::RedirectionConfig#add_skip_rules)
|
42
|
+
#
|
43
|
+
# @return (see Tarquinn::RedirectionConfig#add_skip_rules)
|
44
|
+
def add_skip_config(redirection, *methods, block)
|
45
|
+
config_for(redirection).add_skip_rules(*methods, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Builds a new engine to process a request
|
49
|
+
#
|
50
|
+
# @param controller [ActionController::Base] Controller handling the request
|
51
|
+
#
|
52
|
+
# @return [Tarquinn::RequestHandler]
|
53
|
+
def build(controller)
|
54
|
+
controller = Tarquinn::Controller.new(controller)
|
55
|
+
Tarquinn::RequestHandler.new(configs, controller)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# @api private
|
61
|
+
# @private
|
62
|
+
#
|
63
|
+
# Returns the configuration for one redirection
|
64
|
+
#
|
65
|
+
# When none is configured, a new one is created
|
66
|
+
#
|
67
|
+
# @param redirection [Symbol] redirection_name
|
68
|
+
#
|
69
|
+
# @return [Tarquinn::RedirectionConfig]
|
70
|
+
def config_for(redirection)
|
71
|
+
configs[redirection.to_sym] ||= Tarquinn::RedirectionConfig.new(redirection)
|
72
|
+
end
|
73
|
+
|
74
|
+
# @api private
|
75
|
+
# @private
|
76
|
+
#
|
77
|
+
# Returns all configurations for all redirections for the controller
|
78
|
+
#
|
79
|
+
# @return [Hash<Symbol,Tarquinn::RedirectionConfig>]
|
80
|
+
def configs
|
81
|
+
@configs ||= {}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/tarquinn/version.rb
CHANGED
data/lib/tarquinn.rb
CHANGED
@@ -1,14 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support'
|
2
4
|
require 'active_support/core_ext'
|
3
5
|
|
6
|
+
# @api public
|
7
|
+
#
|
8
|
+
# Concern adding methods for easy redirection controll
|
4
9
|
module Tarquinn
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
autoload :Version, 'tarquinn/version'
|
13
|
+
autoload :RedirectionHandler, 'tarquinn/redirection_handler'
|
14
|
+
autoload :Controller, 'tarquinn/controller'
|
15
|
+
autoload :Condition, 'tarquinn/condition'
|
16
|
+
autoload :RedirectionConfig, 'tarquinn/redirection_config'
|
17
|
+
autoload :RequestHandler, 'tarquinn/request_handler'
|
18
|
+
autoload :RequestHandlerBuilder, 'tarquinn/request_handler_builder'
|
19
|
+
|
12
20
|
require 'tarquinn/class_methods'
|
13
|
-
|
21
|
+
|
22
|
+
# @method self.redirection_rule(redirection, *methods, &block)
|
23
|
+
#
|
24
|
+
# Creates a redirection rule
|
25
|
+
#
|
26
|
+
# The rule name defines which method will be called when checking the path of redirection
|
27
|
+
#
|
28
|
+
# @param (see Tarquinn::ClassMethods#redirection_rule)
|
29
|
+
# @return (see Tarquinn::ClassMethods#redirection_rule)
|
30
|
+
|
31
|
+
# @method self.skip_redirection(redirection, *actions)
|
32
|
+
#
|
33
|
+
# Attaches a condition to skip a redirection based on route (controller action)
|
34
|
+
#
|
35
|
+
# When any of the skip rules is met the redirection is skipped
|
36
|
+
#
|
37
|
+
# @param (see Tarquinn::ClassMethods#skip_redirection)
|
38
|
+
# @return (see Tarquinn::ClassMethods#skip_redirection)
|
39
|
+
|
40
|
+
# @method self.skip_redirection_rule(redirection, *methods, &block)
|
41
|
+
#
|
42
|
+
# Attaches conditions to skip a redirection
|
43
|
+
#
|
44
|
+
# Methods and blocks are ran and if any returns true, the redirec is skipped
|
45
|
+
#
|
46
|
+
# @param (see Tarquinn::ClassMethods#skip_redirection)
|
47
|
+
# @return (see Tarquinn::ClassMethods#skip_redirection)
|
48
|
+
|
49
|
+
# @method self.redirector_builder
|
50
|
+
#
|
51
|
+
# Retruns the RequestHandlerBuilder
|
52
|
+
#
|
53
|
+
# RequestHandlerBuilder will Carry all the configurations and will create
|
54
|
+
# one {RequestHandler} for each request
|
55
|
+
#
|
56
|
+
# @return (see Tarquinn::ClassMethods#redirector_builder)
|
57
|
+
included do
|
58
|
+
before_action :perform_redirection
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# @api private
|
64
|
+
# private
|
65
|
+
#
|
66
|
+
# @return [Tarquinn::RequestHandler] an engine for the controller
|
67
|
+
def redirector_engine
|
68
|
+
self.class.redirector_builder.build(self)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Performs redirection if enabled / needed
|
72
|
+
#
|
73
|
+
# The rules / configuratons are processed in order
|
74
|
+
# and if any is positive, it will be processed
|
75
|
+
#
|
76
|
+
# @return (see Tarquinn::RequestHandler#perform_redirect)
|
77
|
+
def perform_redirection
|
78
|
+
redirector_engine.perform_redirect
|
79
|
+
end
|
14
80
|
end
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
4
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
5
|
+
|
6
|
+
require_relative 'config/application'
|
7
|
+
|
8
|
+
Rails.application.load_tasks
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
/* Application styles */
|
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tarquinn
|
4
|
+
class DummyController < ApplicationController
|
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
|
+
ActionController::Parameters.new({ 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(_); end
|
34
|
+
|
35
|
+
def should_redirect?
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def should_skip_redirect?
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tarquinn
|
4
|
+
class DummyRouteController < ApplicationController
|
5
|
+
include Tarquinn
|
6
|
+
|
7
|
+
def index; end
|
8
|
+
|
9
|
+
def new; end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def redirection
|
14
|
+
'/path'
|
15
|
+
end
|
16
|
+
|
17
|
+
def should_redirect?
|
18
|
+
params[:should_redirect]
|
19
|
+
end
|
20
|
+
|
21
|
+
def condition2
|
22
|
+
params[:redirect]
|
23
|
+
end
|
24
|
+
|
25
|
+
def should_skip?
|
26
|
+
params[:should_skip]
|
27
|
+
end
|
28
|
+
|
29
|
+
def do_skip?
|
30
|
+
params[:skip]
|
31
|
+
end
|
32
|
+
|
33
|
+
def always_redirect
|
34
|
+
true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ApplicationJob < ActiveJob::Base
|
4
|
+
# Automatically retry jobs that encountered a deadlock
|
5
|
+
# retry_on ActiveRecord::Deadlocked
|
6
|
+
|
7
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
8
|
+
# discard_on ActiveJob::DeserializationError
|
9
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<%= csrf_meta_tags %>
|
7
|
+
<%= csp_meta_tag %>
|
8
|
+
|
9
|
+
<%= stylesheet_link_tag "application" %>
|
10
|
+
</head>
|
11
|
+
|
12
|
+
<body>
|
13
|
+
<%= yield %>
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
File without changes
|
File without changes
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
FileUtils.chdir APP_ROOT do
|
14
|
+
# This script is a way to set up or update your development environment automatically.
|
15
|
+
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
|
16
|
+
# Add necessary setup steps to this file.
|
17
|
+
|
18
|
+
puts '== Installing dependencies =='
|
19
|
+
system! 'gem install bundler --conservative'
|
20
|
+
system('bundle check') || system!('bundle install')
|
21
|
+
|
22
|
+
# puts "\n== Copying sample files =="
|
23
|
+
# unless File.exist?("config/database.yml")
|
24
|
+
# FileUtils.cp "config/database.yml.sample", "config/database.yml"
|
25
|
+
# end
|
26
|
+
|
27
|
+
puts "\n== Preparing database =="
|
28
|
+
system! 'bin/rails db:prepare'
|
29
|
+
|
30
|
+
puts "\n== Removing old logs and tempfiles =="
|
31
|
+
system! 'bin/rails log:clear tmp:clear'
|
32
|
+
|
33
|
+
puts "\n== Restarting application server =="
|
34
|
+
system! 'bin/rails restart'
|
35
|
+
end
|