rails_ops 1.4.1 → 1.4.2

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +102 -11
  3. data/Appraisals +11 -11
  4. data/CHANGELOG.md +9 -0
  5. data/Rakefile +3 -5
  6. data/VERSION +1 -1
  7. data/gemfiles/rails_6.0.gemfile +3 -3
  8. data/gemfiles/rails_6.1.gemfile +3 -3
  9. data/gemfiles/rails_7.0.gemfile +3 -3
  10. data/lib/generators/operation/operation_generator.rb +3 -3
  11. data/lib/rails_ops/authorization_backend/abstract.rb +1 -1
  12. data/lib/rails_ops/authorization_backend/can_can_can.rb +3 -1
  13. data/lib/rails_ops/controller_mixin.rb +1 -1
  14. data/lib/rails_ops/hookup/dsl_validator.rb +2 -1
  15. data/lib/rails_ops/hookup.rb +1 -1
  16. data/lib/rails_ops/mixins/authorization.rb +2 -2
  17. data/lib/rails_ops/mixins/model/nesting.rb +22 -23
  18. data/lib/rails_ops/mixins/policies.rb +7 -7
  19. data/lib/rails_ops/mixins/routes.rb +1 -1
  20. data/lib/rails_ops/model_mixins/marshalling.rb +1 -1
  21. data/lib/rails_ops/operation/model/load.rb +2 -4
  22. data/lib/rails_ops/operation/model/update.rb +2 -2
  23. data/lib/rails_ops/operation/model.rb +1 -1
  24. data/lib/rails_ops/operation.rb +7 -4
  25. data/lib/rails_ops/profiler/node.rb +1 -1
  26. data/lib/rails_ops/profiler.rb +1 -1
  27. data/lib/rails_ops.rb +43 -43
  28. data/rails_ops.gemspec +4 -4
  29. data/test/dummy/bin/bundle +1 -1
  30. data/test/dummy/bin/setup +1 -1
  31. data/test/dummy/bin/update +1 -1
  32. data/test/dummy/bin/yarn +5 -7
  33. data/test/dummy/config/environments/production.rb +1 -1
  34. data/test/dummy/config/spring.rb +2 -2
  35. data/test/test_helper.rb +5 -5
  36. data/test/unit/rails_ops/generators/operation_generator_test.rb +10 -12
  37. data/test/unit/rails_ops/mixins/model/deep_nesting_test.rb +69 -10
  38. data/test/unit/rails_ops/mixins/param_authorization_test.rb +3 -3
  39. data/test/unit/rails_ops/mixins/policies_test.rb +2 -2
  40. data/test/unit/rails_ops/operation/update_auth_test.rb +2 -0
  41. data/test/unit/rails_ops/operation/update_lazy_auth_test.rb +1 -0
  42. data/test/unit/rails_ops/operation_test.rb +1 -1
  43. metadata +11 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf07735e6610693ed0a7595e5b85b2fa5c38f0cb1c470a9b7989a2d7105a4152
4
- data.tar.gz: 33b92924b44d06b64309a057fb76fa7bac42c59faad7f67d2de584c819259766
3
+ metadata.gz: 545583c613d3f9b9c7599f93af3351790cc5b223ab3c2a8ec3a7962eb4143e2c
4
+ data.tar.gz: 9bc1a949fd81b6e05744561f76550ae72ddb8c18795de7dce47a6220ba9622a1
5
5
  SHA512:
6
- metadata.gz: 4ce25936523ca89e92e1aad1fbb0e884bd6bcd230afd1faa8e106a48f0f853d1305b1e6621063bc2b538e0a6e1e4ca1d8c8e395356489d552d764baf29410713
7
- data.tar.gz: 970ffa94554885d4bcd9a2351a5b413d245f5f3b1ea7900d0220d1fe7e0d52fa98389025f61a29f7c0b300955741e09d8321502697d4a18235eaf97729952b49
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
- - 'vendor/**/*'
6
- - 'tmp/**/*'
7
- - 'log/**/*'
8
- - '*.gemspec'
7
+ - 'test/dummy/**/*'
9
8
  - 'test/tmp/**/*'
9
+ - 'vendor/**/*'
10
+ - 'rails_ops.gemspec'
10
11
 
11
- DisplayCopNames: true
12
+ # Make sure accessors are on separate lines for diff readability.
13
+ Style/AccessorGrouping:
14
+ EnforcedStyle: separated
12
15
 
13
- Style/SafeNavigation:
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
- Style/IndentArray:
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
- Metrics/LineLength:
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
- Metrics/BlockNesting:
114
+ # Disable variable number naming convention.
115
+ Naming/VariableNumber:
57
116
  Enabled: false
58
117
 
59
- Metrics/BlockLength:
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 "rails-7.0" do
2
- gem "rails", "~> 7.0.1"
1
+ appraise 'rails-7.0' do
2
+ gem 'rails', '~> 7.0.1'
3
3
  end
4
4
 
5
- appraise "rails-6.1" do
6
- gem "rails", "~> 6.1.4"
5
+ appraise 'rails-6.1' do
6
+ gem 'rails', '~> 6.1.4'
7
7
  end
8
8
 
9
- appraise "rails-6.0" do
10
- gem "rails", "~> 6.0.4"
9
+ appraise 'rails-6.0' do
10
+ gem 'rails', '~> 6.0.4'
11
11
  end
12
12
 
13
- appraise "rails-5.2" do
14
- gem "rails", "~> 5.2.6"
13
+ appraise 'rails-5.2' do
14
+ gem 'rails', '~> 5.2.6'
15
15
  end
16
16
 
17
- appraise "rails-5.1" do
18
- gem "rails", "~> 5.1.7"
19
- end
17
+ appraise 'rails-5.1' do
18
+ gem 'rails', '~> 5.1.7'
19
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
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`.
3
12
 
4
13
  ## 1.4.1 (2023-02-21)
5
14
 
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 = IO.read('VERSION').chomp
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', '0.47.1'
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.open('rails_ops.gemspec', 'w') { |f| f.write(gemspec.to_ruby.strip) }
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
+ 1.4.2
@@ -1,7 +1,7 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- gem "rails", "~> 6.0.4"
5
+ gem 'rails', '~> 6.0.4'
6
6
 
7
- gemspec path: "../"
7
+ gemspec path: '../'
@@ -1,7 +1,7 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- gem "rails", "~> 6.1.4"
5
+ gem 'rails', '~> 6.1.4'
6
6
 
7
- gemspec path: "../"
7
+ gemspec path: '../'
@@ -1,7 +1,7 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- gem "rails", "~> 7.0.1"
5
+ gem 'rails', '~> 7.0.1'
6
6
 
7
- gemspec path: "../"
7
+ gemspec path: '../'
@@ -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 = name.underscore
13
- @underscored_pluralized_name = name.underscore.pluralize
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(index show new edit).each do |view|
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
@@ -1,5 +1,6 @@
1
1
  class RailsOps::Hookup::DSLValidator
2
- attr_reader :error, :trace
2
+ attr_reader :error
3
+ attr_reader :trace
3
4
 
4
5
  def initialize(hooks)
5
6
  @hooks = hooks
@@ -55,7 +55,7 @@ class RailsOps::Hookup
55
55
 
56
56
  hooks = []
57
57
 
58
- @hooks.slice('*', operation.class.name).values.each do |hooks_by_event|
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
- @_authorize_called ||= false
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
- @_authorize_called = true
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
- 'This is not supported by nest_model_op.'
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
- if inverse_reflection.options[:autosave] != false
66
- fail "Association #{inverse_reflection.name} of #{inverse_reflection.active_record} has :autosave turned on. "\
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,12 +71,12 @@ module RailsOps::Mixins::Model::Nesting
73
71
  # ---------------------------------------------------------------
74
72
  self._nested_model_ops = _nested_model_ops.merge(
75
73
  attribute => {
76
- klass: klass,
77
- param_key: param_key,
78
- attribute_name: reflection.class_name.underscore,
79
- params_proc: params_block,
74
+ klass: klass,
75
+ param_key: param_key,
76
+ attribute_name: reflection.class_name.underscore,
77
+ params_proc: params_block,
80
78
  lookup_via_id_on_update: lookup_via_id_on_update,
81
- allow_id: allow_id
79
+ allow_id: allow_id
82
80
  }
83
81
  )
84
82
  end
@@ -104,7 +102,7 @@ module RailsOps::Mixins::Model::Nesting
104
102
 
105
103
  def build_nested_model_ops(action)
106
104
  # Validate action
107
- fail 'Unsupported action.' unless %i(create update).include?(action)
105
+ fail 'Unsupported action.' unless %i[create update].include?(action)
108
106
 
109
107
  # Make sure that this method can only be run once per operation
110
108
  fail 'Nested model operations can only be built once.' if @nested_model_ops
@@ -126,11 +124,12 @@ module RailsOps::Mixins::Model::Nesting
126
124
  # Wrap parameters for nested model operation
127
125
  param_key = config[:param_key] || config[:klass].model.model_name.param_key
128
126
 
129
- if action == :create
127
+ case action
128
+ when :create
130
129
  wrapped_params = {
131
130
  param_key => op_params
132
131
  }
133
- elsif action == :update
132
+ when :update
134
133
  if config[:lookup_via_id_on_update]
135
134
  foreign_key = model.class.reflect_on_association(attribute).foreign_key
136
135
  id = model.send(foreign_key)
@@ -139,7 +138,7 @@ module RailsOps::Mixins::Model::Nesting
139
138
  end
140
139
 
141
140
  wrapped_params = {
142
- :id => id,
141
+ :id => id,
143
142
  param_key => op_params
144
143
  }
145
144
  else
@@ -173,15 +172,15 @@ module RailsOps::Mixins::Model::Nesting
173
172
  # line also makes sure a model is built.
174
173
  model.validate!
175
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
+
176
178
  # Validate all unchanged nested models as the above call to "validate!" only validates
177
179
  # associations that are changed.
178
- @nested_model_ops.keys.each do |attribute|
180
+ @nested_model_ops.each_key do |attribute|
179
181
  model.send(attribute).validate!
180
182
  end
181
183
 
182
- # Make sure nested model operations are build
183
- fail 'Nested model operations are not built yet. Make sure the model is built.' unless @nested_model_ops
184
-
185
184
  @nested_model_ops.each do |attribute, op|
186
185
  # Run the nested model operation and fail hard if a validation error
187
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
- :on_init,
10
- :before_perform,
11
- :after_perform,
12
- :before_nested_model_ops,
13
- :before_model_save
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 = Hash[POLICY_CHAIN_KEYS.map { |key| [key, [].freeze] }]
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
- @container ||= Class.new do
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(@parent_op).freeze
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(shared exclusive).include?(lock_mode)
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
@@ -70,7 +70,7 @@ class RailsOps::Operation::Model < RailsOps::Operation
70
70
  end
71
71
 
72
72
  # Set virtual STI name if given.
73
- if model_class && model_class.name
73
+ if model_class&.name
74
74
  _model_class.virtual_sti_name = model_class.name
75
75
  end
76
76
 
@@ -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
- if context_or_params.is_a?(RailsOps::Context)
42
+ case context_or_params
43
+ when RailsOps::Context
43
44
  context = context_or_params
44
- elsif context_or_params.is_a?(Hash) || context_or_params.is_a?(ActionController::Parameters)
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
 
@@ -4,7 +4,7 @@ module RailsOps
4
4
  @object_id = object_id
5
5
  @description = description
6
6
  @parent = parent
7
- parent.add_child(self) if parent
7
+ parent&.add_child(self)
8
8
  @children = []
9
9
  @erroneous = false
10
10
  @t_start = Time.now