rails_ops 1.4.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +102 -11
- data/Appraisals +11 -11
- data/CHANGELOG.md +15 -0
- data/Rakefile +3 -5
- data/VERSION +1 -1
- data/gemfiles/rails_6.0.gemfile +3 -3
- data/gemfiles/rails_6.1.gemfile +3 -3
- data/gemfiles/rails_7.0.gemfile +3 -3
- data/lib/generators/operation/operation_generator.rb +3 -3
- data/lib/rails_ops/authorization_backend/abstract.rb +1 -1
- data/lib/rails_ops/authorization_backend/can_can_can.rb +3 -1
- data/lib/rails_ops/controller_mixin.rb +1 -1
- data/lib/rails_ops/hookup/dsl_validator.rb +2 -1
- data/lib/rails_ops/hookup.rb +1 -1
- data/lib/rails_ops/mixins/authorization.rb +2 -2
- data/lib/rails_ops/mixins/model/nesting.rb +23 -23
- data/lib/rails_ops/mixins/policies.rb +7 -7
- data/lib/rails_ops/mixins/routes.rb +1 -1
- data/lib/rails_ops/model_mixins/marshalling.rb +1 -1
- data/lib/rails_ops/operation/model/load.rb +2 -4
- data/lib/rails_ops/operation/model/update.rb +2 -2
- data/lib/rails_ops/operation/model.rb +1 -1
- data/lib/rails_ops/operation.rb +7 -4
- data/lib/rails_ops/profiler/node.rb +1 -1
- data/lib/rails_ops/profiler.rb +1 -1
- data/lib/rails_ops.rb +43 -43
- data/rails_ops.gemspec +19 -38
- data/test/dummy/bin/bundle +1 -1
- data/test/dummy/bin/setup +1 -1
- data/test/dummy/bin/update +1 -1
- data/test/dummy/bin/yarn +5 -7
- data/test/dummy/config/environments/production.rb +1 -1
- data/test/dummy/config/spring.rb +2 -2
- data/test/test_helper.rb +5 -5
- data/test/unit/rails_ops/generators/operation_generator_test.rb +10 -12
- data/test/unit/rails_ops/mixins/model/deep_nesting_test.rb +69 -10
- data/test/unit/rails_ops/mixins/param_authorization_test.rb +3 -3
- data/test/unit/rails_ops/mixins/policies_test.rb +2 -2
- data/test/unit/rails_ops/operation/update_auth_test.rb +2 -0
- data/test/unit/rails_ops/operation/update_lazy_auth_test.rb +1 -0
- data/test/unit/rails_ops/operation_test.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 545583c613d3f9b9c7599f93af3351790cc5b223ab3c2a8ec3a7962eb4143e2c
|
4
|
+
data.tar.gz: 9bc1a949fd81b6e05744561f76550ae72ddb8c18795de7dce47a6220ba9622a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23c48dbf356b7aa7032d2be737a93e405bd7fd1e63148d28f8c05036cf709a7c20e4951ec76dcfa72e55a71bdcbb5361bb67a29fcd3f13aba45c6b1e52592aec
|
7
|
+
data.tar.gz: 5e9d9889e87a6a98450aa97d0b24487cfe3526376b1cb05dc0ec90d899b0372a93ca3675485a7491cb23a02fb80644e579355f545ffb5ce23e343af61a8a7e96
|
data/.rubocop.yml
CHANGED
@@ -1,79 +1,151 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.3
|
3
|
-
|
3
|
+
DisplayCopNames: true
|
4
|
+
NewCops: enable
|
5
|
+
SuggestExtensions: false
|
4
6
|
Exclude:
|
5
|
-
- '
|
6
|
-
- 'tmp/**/*'
|
7
|
-
- 'log/**/*'
|
8
|
-
- '*.gemspec'
|
7
|
+
- 'test/dummy/**/*'
|
9
8
|
- 'test/tmp/**/*'
|
9
|
+
- 'vendor/**/*'
|
10
|
+
- 'rails_ops.gemspec'
|
10
11
|
|
11
|
-
|
12
|
+
# Make sure accessors are on separate lines for diff readability.
|
13
|
+
Style/AccessorGrouping:
|
14
|
+
EnforcedStyle: separated
|
12
15
|
|
13
|
-
|
16
|
+
# Cop would break a lot of existing code.
|
17
|
+
Style/OptionalBooleanParameter:
|
14
18
|
Enabled: false
|
15
19
|
|
20
|
+
# Multiline hashes should be aligned cleanly as a table to improve readability.
|
21
|
+
Layout/HashAlignment:
|
22
|
+
EnforcedHashRocketStyle: table
|
23
|
+
EnforcedColonStyle: table
|
24
|
+
|
25
|
+
# Template style is easier on the eyes.
|
26
|
+
Style/FormatStringToken:
|
27
|
+
EnforcedStyle: template
|
28
|
+
|
29
|
+
# file. This will be addressed when approaching the first ruby 3 application.
|
16
30
|
Style/FrozenStringLiteralComment:
|
17
31
|
Enabled: false
|
18
32
|
|
33
|
+
# Double negation is very useful to make sure you have a boolean in hand. Use it
|
34
|
+
# wisely though and know what you're doing.
|
19
35
|
Style/DoubleNegation:
|
20
36
|
Enabled: false
|
21
37
|
|
38
|
+
# Depending on the case, [].include? can be a lot harder to read and less
|
39
|
+
# expressive than multiple comparisons.
|
40
|
+
Style/MultipleComparison:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
# Over time, the ruby guide changed from raise to fail back to raise. Both fail
|
44
|
+
# and raise are programatically exactly the same and our decision fell to "fail"
|
45
|
+
# for all kinds of exceptions.
|
22
46
|
Style/SignalException:
|
23
47
|
EnforcedStyle: only_fail
|
24
48
|
|
49
|
+
# Enforced styles can sometimes be hard to read.
|
25
50
|
Style/ConditionalAssignment:
|
26
51
|
Enabled: false
|
27
52
|
|
28
|
-
|
53
|
+
# Enforce consistent array indentation.
|
54
|
+
Layout/FirstArrayElementIndentation:
|
29
55
|
EnforcedStyle: consistent
|
30
56
|
|
57
|
+
# Disable layout cop because methods just consisting of a number of returns
|
58
|
+
# would look very odd with an extra empty line between each return.
|
59
|
+
Layout/EmptyLineAfterGuardClause:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
# While you should try to keep your code as expressive and short as possible,
|
63
|
+
# limitting lengths hardly is over the top.
|
31
64
|
Metrics/MethodLength:
|
32
65
|
Enabled: false
|
33
66
|
|
67
|
+
# While you should try to keep your code as expressive and short as possible,
|
68
|
+
# limitting lengths hardly is over the top.
|
34
69
|
Metrics/ClassLength:
|
35
70
|
Enabled: false
|
36
71
|
|
72
|
+
# While you should try to keep your code as expressive and short as possible,
|
73
|
+
# limitting lengths hardly is over the top.
|
37
74
|
Metrics/ModuleLength:
|
38
75
|
Enabled: false
|
39
76
|
|
77
|
+
# While you should try to keep your code as expressive and short as possible,
|
78
|
+
# limitting lengths hardly is over the top.
|
79
|
+
Metrics/BlockLength:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
# While not always desirable, it can be useful to have a lot of keyword
|
83
|
+
# arguments on certain methods. Try to avoid it though.
|
40
84
|
Metrics/ParameterLists:
|
41
85
|
Max: 5
|
42
86
|
CountKeywordArgs: false
|
43
87
|
|
88
|
+
# The results of this cop sometimes seemed arbitrary and can signifficantly
|
89
|
+
# restrict certain styles of coding.
|
44
90
|
Metrics/AbcSize:
|
45
91
|
Enabled: False
|
46
92
|
|
93
|
+
# The results of this cop sometimes seemed arbitrary and can signifficantly
|
94
|
+
# restrict certain styles of coding.
|
47
95
|
Metrics/CyclomaticComplexity:
|
48
96
|
Enabled: False
|
49
97
|
|
98
|
+
# The results of this cop sometimes seemed arbitrary and can signifficantly
|
99
|
+
# restrict certain styles of coding.
|
50
100
|
Metrics/PerceivedComplexity:
|
51
101
|
Enabled: False
|
52
102
|
|
53
|
-
|
103
|
+
# In certain cases, "excessive" block nesting might just be useful. Try to keep
|
104
|
+
# this down as much as possible though.
|
105
|
+
Metrics/BlockNesting:
|
106
|
+
Enabled: false
|
107
|
+
|
108
|
+
# A line length of 80 is not considered to be temporary anymore. That's why line
|
109
|
+
# length is doubled to 160. If absolutely necessary, create a temporary rubocop
|
110
|
+
# exclusion for the lines in question.
|
111
|
+
Layout/LineLength:
|
54
112
|
Max: 160
|
55
113
|
|
56
|
-
|
114
|
+
# Disable variable number naming convention.
|
115
|
+
Naming/VariableNumber:
|
57
116
|
Enabled: false
|
58
117
|
|
59
|
-
|
118
|
+
# Disable method parameter naming convention.
|
119
|
+
Naming/MethodParameterName:
|
60
120
|
Enabled: false
|
61
121
|
|
122
|
+
# Depending on the surrounding code, even simple if/unless clauses may be more
|
123
|
+
# descriptive when on multiple lines.
|
62
124
|
Style/IfUnlessModifier:
|
63
125
|
Enabled: false
|
64
126
|
|
127
|
+
# In most cases, timing does not allow documenting each and every bit of source
|
128
|
+
# code. Do not hesitate to enable this cop otherwise.
|
65
129
|
Style/Documentation:
|
66
130
|
Enabled: false
|
67
131
|
|
132
|
+
# Return should be used whenever there is more than one statement or line in a
|
133
|
+
# method. This helps avoiding programming mistakes. This is not enforced yet as
|
134
|
+
# this would require a custom cop. However, to allow this style of programming,
|
135
|
+
# the RedundantReturn cop needs to be disabled.
|
68
136
|
Style/RedundantReturn:
|
69
137
|
Enabled: false
|
70
138
|
|
139
|
+
# Non-ascii comments can be useful sometimes.
|
71
140
|
Style/AsciiComments:
|
72
141
|
Enabled: false
|
73
142
|
|
143
|
+
# Depending on the case, if/unless can be more descriptive than guard clauses.
|
74
144
|
Style/GuardClause:
|
75
145
|
Enabled: false
|
76
146
|
|
147
|
+
# For technical reasons, nested and compact styles must be mixed in certain
|
148
|
+
# applications.
|
77
149
|
Style/ClassAndModuleChildren:
|
78
150
|
Enabled: false
|
79
151
|
EnforcedStyle: compact
|
@@ -81,8 +153,27 @@ Style/ClassAndModuleChildren:
|
|
81
153
|
- nested
|
82
154
|
- compact
|
83
155
|
|
156
|
+
# Depending on the case, it may be more descriptive to use i.e. == 0 instead of
|
157
|
+
# .zero?, especially when testing against multiple numbers.
|
84
158
|
Style/NumericPredicate:
|
85
159
|
Enabled: false
|
86
160
|
|
161
|
+
# Detection is not implemented in a reliable manner for all cases which can lead
|
162
|
+
# to false positives and negatives.
|
87
163
|
Style/FormatString:
|
88
164
|
Enabled: false
|
165
|
+
|
166
|
+
# Do not require MFA, as gems checked with sitrox_standards are only pushed to the
|
167
|
+
# internal repo
|
168
|
+
Gemspec/RequireMFA:
|
169
|
+
Enabled: false
|
170
|
+
|
171
|
+
# Use explicit style
|
172
|
+
Naming/BlockForwarding:
|
173
|
+
Enabled: true
|
174
|
+
EnforcedStyle: explicit
|
175
|
+
|
176
|
+
# Don't require gemspec dependencies to be versioned. While it's generally a good
|
177
|
+
# idea to require specifying versions of dependencies, we don't want to enforce it.
|
178
|
+
Gemspec/DependencyVersion:
|
179
|
+
Enabled: false
|
data/Appraisals
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
appraise
|
2
|
-
gem
|
1
|
+
appraise 'rails-7.0' do
|
2
|
+
gem 'rails', '~> 7.0.1'
|
3
3
|
end
|
4
4
|
|
5
|
-
appraise
|
6
|
-
gem
|
5
|
+
appraise 'rails-6.1' do
|
6
|
+
gem 'rails', '~> 6.1.4'
|
7
7
|
end
|
8
8
|
|
9
|
-
appraise
|
10
|
-
gem
|
9
|
+
appraise 'rails-6.0' do
|
10
|
+
gem 'rails', '~> 6.0.4'
|
11
11
|
end
|
12
12
|
|
13
|
-
appraise
|
14
|
-
gem
|
13
|
+
appraise 'rails-5.2' do
|
14
|
+
gem 'rails', '~> 5.2.6'
|
15
15
|
end
|
16
16
|
|
17
|
-
appraise
|
18
|
-
gem
|
19
|
-
end
|
17
|
+
appraise 'rails-5.1' do
|
18
|
+
gem 'rails', '~> 5.1.7'
|
19
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.4.2 (2023-03-20)
|
4
|
+
|
5
|
+
* Update the `operation` generator such that it complies with the naming
|
6
|
+
conventions laid out in [Placing and naming
|
7
|
+
operations](https://github.com/sitrox/rails_ops#placing-and-naming-operations).
|
8
|
+
The path were the operations reside and the validation schema key are now
|
9
|
+
generated in singular.
|
10
|
+
|
11
|
+
Internal reference: `#111055`.
|
12
|
+
|
13
|
+
## 1.4.1 (2023-02-21)
|
14
|
+
|
15
|
+
* Fix specifying custom [param_key](README.md#param-key) when nesting model
|
16
|
+
operations
|
17
|
+
|
3
18
|
## 1.4.0 (2023-02-21)
|
4
19
|
|
5
20
|
### Changes
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ task default: :test
|
|
7
7
|
task :gemspec do
|
8
8
|
gemspec = Gem::Specification.new do |spec|
|
9
9
|
spec.name = 'rails_ops'
|
10
|
-
spec.version =
|
10
|
+
spec.version = File.read('VERSION').chomp
|
11
11
|
spec.authors = ['Sitrox']
|
12
12
|
spec.summary = 'An operations service layer for rails projects.'
|
13
13
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
@@ -22,7 +22,7 @@ task :gemspec do
|
|
22
22
|
spec.add_development_dependency 'cancancan'
|
23
23
|
spec.add_development_dependency 'pry'
|
24
24
|
spec.add_development_dependency 'colorize'
|
25
|
-
spec.add_development_dependency 'rubocop', '
|
25
|
+
spec.add_development_dependency 'rubocop', '1.45.1'
|
26
26
|
spec.add_development_dependency 'sprockets-rails'
|
27
27
|
spec.add_dependency 'active_type', '>= 1.3.0'
|
28
28
|
spec.add_dependency 'minitest'
|
@@ -31,11 +31,9 @@ task :gemspec do
|
|
31
31
|
spec.add_dependency 'schemacop', '>= 2.4.2', '<= 3.1'
|
32
32
|
end
|
33
33
|
|
34
|
-
File.
|
34
|
+
File.write('rails_ops.gemspec', gemspec.to_ruby.strip)
|
35
35
|
end
|
36
36
|
|
37
|
-
require 'rake/testtask'
|
38
|
-
|
39
37
|
Rake::TestTask.new do |t|
|
40
38
|
t.pattern = 'test/unit/**/*_test.rb'
|
41
39
|
t.verbose = false
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.2
|
data/gemfiles/rails_6.0.gemfile
CHANGED
data/gemfiles/rails_6.1.gemfile
CHANGED
data/gemfiles/rails_7.0.gemfile
CHANGED
@@ -9,8 +9,8 @@ class OperationGenerator < Rails::Generators::NamedBase
|
|
9
9
|
|
10
10
|
def add_operations
|
11
11
|
@class_name = name.classify
|
12
|
-
@underscored_name =
|
13
|
-
@underscored_pluralized_name =
|
12
|
+
@underscored_name = @class_name.underscore
|
13
|
+
@underscored_pluralized_name = @class_name.underscore.pluralize
|
14
14
|
|
15
15
|
operations_path = 'app/operations/'
|
16
16
|
|
@@ -51,7 +51,7 @@ class OperationGenerator < Rails::Generators::NamedBase
|
|
51
51
|
end
|
52
52
|
views_folder += @underscored_pluralized_name.to_s
|
53
53
|
|
54
|
-
%w
|
54
|
+
%w[index show new edit].each do |view|
|
55
55
|
template 'view.erb', "#{views_folder}/#{view}.html.haml"
|
56
56
|
end
|
57
57
|
end
|
@@ -7,7 +7,7 @@ module RailsOps::AuthorizationBackend
|
|
7
7
|
def exception_class
|
8
8
|
@exception_class ||= self.class::EXCEPTION_CLASS.constantize
|
9
9
|
rescue NameError
|
10
|
-
fail "Unable to constantize exception class #{self.class::EXCEPTION_CLASS.inspect} "\
|
10
|
+
fail "Unable to constantize exception class #{self.class::EXCEPTION_CLASS.inspect} " \
|
11
11
|
"for authorization backend #{self.class.name}. Is the library loaded?"
|
12
12
|
end
|
13
13
|
end
|
@@ -5,8 +5,10 @@ module RailsOps::AuthorizationBackend
|
|
5
5
|
EXCEPTION_CLASS = 'CanCan::AccessDenied'.freeze
|
6
6
|
|
7
7
|
def initialize
|
8
|
+
super
|
9
|
+
|
8
10
|
unless defined?(CanCanCan)
|
9
|
-
fail 'RailsOps is configured to use CanCanCan authorization'\
|
11
|
+
fail 'RailsOps is configured to use CanCanCan authorization' \
|
10
12
|
"backend, but the Gem 'cancancan' does not appear to be installed."
|
11
13
|
end
|
12
14
|
end
|
@@ -100,7 +100,7 @@ module RailsOps
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def model?
|
103
|
-
!!(@model || op? && op.respond_to?(:model) && op.model)
|
103
|
+
!!(@model || (op? && op.respond_to?(:model) && op.model))
|
104
104
|
end
|
105
105
|
|
106
106
|
# Filters the `params` hash for use with RailsOps. This removes certain
|
data/lib/rails_ops/hookup.rb
CHANGED
@@ -55,7 +55,7 @@ class RailsOps::Hookup
|
|
55
55
|
|
56
56
|
hooks = []
|
57
57
|
|
58
|
-
@hooks.slice('*', operation.class.name).
|
58
|
+
@hooks.slice('*', operation.class.name).each_value do |hooks_by_event|
|
59
59
|
hooks += hooks_by_event.slice('*', event).values.flatten || []
|
60
60
|
end
|
61
61
|
|
@@ -48,12 +48,12 @@ module RailsOps::Mixins::Authorization
|
|
48
48
|
|
49
49
|
# Determines whether authorize has been called for this operation.
|
50
50
|
def authorize_called?
|
51
|
-
@
|
51
|
+
@authorize_called ||= false
|
52
52
|
end
|
53
53
|
|
54
54
|
# Manually marks the authorization as called for this operation.
|
55
55
|
def authorize_called!
|
56
|
-
@
|
56
|
+
@authorize_called = true
|
57
57
|
end
|
58
58
|
|
59
59
|
# Operations within the given block will have disabled authorization.
|
@@ -31,15 +31,15 @@ module RailsOps::Mixins::Model::Nesting
|
|
31
31
|
if reflection.nil?
|
32
32
|
fail "Association #{attribute} could not be found for #{model.model_name}."
|
33
33
|
elsif !reflection.belongs_to?
|
34
|
-
fail 'Method nest_model_op only supports :belongs_to associations, '\
|
35
|
-
"but association #{attribute} of model #{model.model_name} is a "\
|
34
|
+
fail 'Method nest_model_op only supports :belongs_to associations, ' \
|
35
|
+
"but association #{attribute} of model #{model.model_name} is a " \
|
36
36
|
"#{reflection.macro} association."
|
37
37
|
elsif reflection.options[:autosave] != false
|
38
|
-
fail "Association #{attribute} of #{model.model_name} has :autosave turned on. "\
|
38
|
+
fail "Association #{attribute} of #{model.model_name} has :autosave turned on. " \
|
39
39
|
'This is not supported by nest_model_op.'
|
40
40
|
elsif !reflection.options[:validate]
|
41
|
-
fail "Association #{attribute} of #{model.model_name} has :validate turned off. "\
|
42
|
-
|
41
|
+
fail "Association #{attribute} of #{model.model_name} has :validate turned off. " \
|
42
|
+
'This is not supported by nest_model_op.'
|
43
43
|
end
|
44
44
|
|
45
45
|
# ---------------------------------------------------------------
|
@@ -61,11 +61,9 @@ module RailsOps::Mixins::Model::Nesting
|
|
61
61
|
# ---------------------------------------------------------------
|
62
62
|
# Validate inverse association reflection if given
|
63
63
|
# ---------------------------------------------------------------
|
64
|
-
if (inverse_reflection = reflection.inverse_of)
|
65
|
-
|
66
|
-
|
67
|
-
'This is not supported by nest_model_op.'
|
68
|
-
end
|
64
|
+
if (inverse_reflection = reflection.inverse_of) && (inverse_reflection.options[:autosave] != false)
|
65
|
+
fail "Association #{inverse_reflection.name} of #{inverse_reflection.active_record} has :autosave turned on. " \
|
66
|
+
'This is not supported by nest_model_op.'
|
69
67
|
end
|
70
68
|
|
71
69
|
# ---------------------------------------------------------------
|
@@ -73,11 +71,12 @@ module RailsOps::Mixins::Model::Nesting
|
|
73
71
|
# ---------------------------------------------------------------
|
74
72
|
self._nested_model_ops = _nested_model_ops.merge(
|
75
73
|
attribute => {
|
76
|
-
klass:
|
77
|
-
|
78
|
-
|
74
|
+
klass: klass,
|
75
|
+
param_key: param_key,
|
76
|
+
attribute_name: reflection.class_name.underscore,
|
77
|
+
params_proc: params_block,
|
79
78
|
lookup_via_id_on_update: lookup_via_id_on_update,
|
80
|
-
allow_id:
|
79
|
+
allow_id: allow_id
|
81
80
|
}
|
82
81
|
)
|
83
82
|
end
|
@@ -103,7 +102,7 @@ module RailsOps::Mixins::Model::Nesting
|
|
103
102
|
|
104
103
|
def build_nested_model_ops(action)
|
105
104
|
# Validate action
|
106
|
-
fail 'Unsupported action.' unless %i
|
105
|
+
fail 'Unsupported action.' unless %i[create update].include?(action)
|
107
106
|
|
108
107
|
# Make sure that this method can only be run once per operation
|
109
108
|
fail 'Nested model operations can only be built once.' if @nested_model_ops
|
@@ -123,13 +122,14 @@ module RailsOps::Mixins::Model::Nesting
|
|
123
122
|
end
|
124
123
|
|
125
124
|
# Wrap parameters for nested model operation
|
126
|
-
param_key
|
125
|
+
param_key = config[:param_key] || config[:klass].model.model_name.param_key
|
127
126
|
|
128
|
-
|
127
|
+
case action
|
128
|
+
when :create
|
129
129
|
wrapped_params = {
|
130
130
|
param_key => op_params
|
131
131
|
}
|
132
|
-
|
132
|
+
when :update
|
133
133
|
if config[:lookup_via_id_on_update]
|
134
134
|
foreign_key = model.class.reflect_on_association(attribute).foreign_key
|
135
135
|
id = model.send(foreign_key)
|
@@ -138,7 +138,7 @@ module RailsOps::Mixins::Model::Nesting
|
|
138
138
|
end
|
139
139
|
|
140
140
|
wrapped_params = {
|
141
|
-
:id
|
141
|
+
:id => id,
|
142
142
|
param_key => op_params
|
143
143
|
}
|
144
144
|
else
|
@@ -172,15 +172,15 @@ module RailsOps::Mixins::Model::Nesting
|
|
172
172
|
# line also makes sure a model is built.
|
173
173
|
model.validate!
|
174
174
|
|
175
|
+
# Make sure nested model operations are built
|
176
|
+
fail 'Nested model operations are not built yet. Make sure the model is built.' unless @nested_model_ops
|
177
|
+
|
175
178
|
# Validate all unchanged nested models as the above call to "validate!" only validates
|
176
179
|
# associations that are changed.
|
177
|
-
@nested_model_ops.
|
180
|
+
@nested_model_ops.each_key do |attribute|
|
178
181
|
model.send(attribute).validate!
|
179
182
|
end
|
180
183
|
|
181
|
-
# Make sure nested model operations are build
|
182
|
-
fail 'Nested model operations are not built yet. Make sure the model is built.' unless @nested_model_ops
|
183
|
-
|
184
184
|
@nested_model_ops.each do |attribute, op|
|
185
185
|
# Run the nested model operation and fail hard if a validation error
|
186
186
|
# arises. This should generally not happen as the whole hierarchy has been
|
@@ -5,17 +5,17 @@
|
|
5
5
|
module RailsOps::Mixins::Policies
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
POLICY_CHAIN_KEYS = [
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
POLICY_CHAIN_KEYS = %i[
|
9
|
+
on_init
|
10
|
+
before_perform
|
11
|
+
after_perform
|
12
|
+
before_nested_model_ops
|
13
|
+
before_model_save
|
14
14
|
].freeze
|
15
15
|
|
16
16
|
included do
|
17
17
|
class_attribute :_policy_chains
|
18
|
-
self._policy_chains =
|
18
|
+
self._policy_chains = POLICY_CHAIN_KEYS.map { |key| [key, [].freeze] }.to_h
|
19
19
|
end
|
20
20
|
|
21
21
|
module ClassMethods
|
@@ -6,7 +6,7 @@ module RailsOps::Mixins::Routes
|
|
6
6
|
# this class on the first call. This is not thread-safe, but the worst case is
|
7
7
|
# that this is performed more than once.
|
8
8
|
def self.container_class
|
9
|
-
@
|
9
|
+
@container_class ||= Class.new do
|
10
10
|
include Rails.application.routes.url_helpers
|
11
11
|
|
12
12
|
attr_reader :url_options
|
@@ -5,7 +5,7 @@ module RailsOps
|
|
5
5
|
# with default procs which is not supported by `Marshal.dump`. This mixin
|
6
6
|
# therefore excludes this instance variable from being dumped and loaded.
|
7
7
|
module Marshalling
|
8
|
-
UNMARSHALED_VARIABLES = %i
|
8
|
+
UNMARSHALED_VARIABLES = %i[@parent_op].freeze
|
9
9
|
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
|
@@ -45,7 +45,7 @@ class RailsOps::Operation::Model::Load < RailsOps::Operation::Model
|
|
45
45
|
# that currently, :shared only works for MySql, Postgresql and Oracle DB,
|
46
46
|
# other adapters always use the exclusive lock.
|
47
47
|
def self.lock_mode(lock_mode)
|
48
|
-
fail "Unknown lock mode #{lock_mode}" unless %i
|
48
|
+
fail "Unknown lock mode #{lock_mode}" unless %i[shared exclusive].include?(lock_mode)
|
49
49
|
|
50
50
|
self._lock_mode = lock_mode
|
51
51
|
end
|
@@ -108,12 +108,10 @@ class RailsOps::Operation::Model::Load < RailsOps::Operation::Model
|
|
108
108
|
adapter_type = ActiveRecord::Base.connection.adapter_name.downcase.to_sym
|
109
109
|
|
110
110
|
case adapter_type
|
111
|
-
when :mysql, :mysql2
|
111
|
+
when :mysql, :mysql2, :oracleenhanced
|
112
112
|
return 'LOCK IN SHARE MODE'
|
113
113
|
when :postgresql
|
114
114
|
return 'FOR SHARE'
|
115
|
-
when :oracleenhanced
|
116
|
-
return 'LOCK IN SHARE MODE'
|
117
115
|
end
|
118
116
|
|
119
117
|
# Don't return anything, which will make the `lock` statement
|
@@ -20,8 +20,8 @@ class RailsOps::Operation::Model::Update < RailsOps::Operation::Model::Load
|
|
20
20
|
if self.class._model_authorization_lazy
|
21
21
|
if load_model_authorization_action.nil?
|
22
22
|
fail RailsOps::Exceptions::NoAuthorizationPerformed,
|
23
|
-
"Operation #{self.class.name} must specify a "\
|
24
|
-
'load_model_authorization_action because model '\
|
23
|
+
"Operation #{self.class.name} must specify a " \
|
24
|
+
'load_model_authorization_action because model ' \
|
25
25
|
'authorization is configured to be lazy.'
|
26
26
|
else
|
27
27
|
authorize_model! load_model_authorization_action, model
|
data/lib/rails_ops/operation.rb
CHANGED
@@ -39,9 +39,10 @@ class RailsOps::Operation
|
|
39
39
|
# @param params [Hash] Optional parameters hash
|
40
40
|
def initialize(context_or_params = {}, params = {})
|
41
41
|
# Handle parameter signature
|
42
|
-
|
42
|
+
case context_or_params
|
43
|
+
when RailsOps::Context
|
43
44
|
context = context_or_params
|
44
|
-
|
45
|
+
when Hash, ActionController::Parameters
|
45
46
|
context = nil
|
46
47
|
params = context_or_params
|
47
48
|
end
|
@@ -80,7 +81,9 @@ class RailsOps::Operation
|
|
80
81
|
|
81
82
|
# Returns a copy of the operation's params, wrapped in an OpenStruct object.
|
82
83
|
def osparams
|
84
|
+
# rubocop: disable Style/OpenStructUse
|
83
85
|
@osparams ||= OpenStruct.new(params)
|
86
|
+
# rubocop: enable Style/OpenStructUse
|
84
87
|
end
|
85
88
|
|
86
89
|
# Return a hash of parameters with all sensitive data replaced.
|
@@ -131,7 +134,7 @@ class RailsOps::Operation
|
|
131
134
|
if params
|
132
135
|
begin
|
133
136
|
inspected_params = inspect_params(filtered_params)
|
134
|
-
rescue
|
137
|
+
rescue StandardError
|
135
138
|
inspected_params = '<could not inspect params>'
|
136
139
|
end
|
137
140
|
inspection += " (#{inspected_params})"
|
@@ -222,7 +225,7 @@ class RailsOps::Operation
|
|
222
225
|
# elegant and transparent approach as explained in the issue.
|
223
226
|
def with_rollback_on_exception(&_block)
|
224
227
|
yield
|
225
|
-
rescue => e
|
228
|
+
rescue StandardError => e
|
226
229
|
fail RailsOps::Exceptions::RollbackRequired, e, e.backtrace
|
227
230
|
end
|
228
231
|
|