rails_ops 1.4.1 → 1.4.3

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +102 -11
  3. data/Appraisals +11 -11
  4. data/CHANGELOG.md +18 -0
  5. data/README.md +12 -2
  6. data/Rakefile +3 -5
  7. data/VERSION +1 -1
  8. data/gemfiles/rails_6.0.gemfile +3 -3
  9. data/gemfiles/rails_6.1.gemfile +3 -3
  10. data/gemfiles/rails_7.0.gemfile +3 -3
  11. data/lib/generators/operation/operation_generator.rb +56 -9
  12. data/lib/generators/operation/templates/controller.erb +34 -23
  13. data/lib/generators/operation/templates/controller_wrapper.erb +14 -0
  14. data/lib/rails_ops/authorization_backend/abstract.rb +1 -1
  15. data/lib/rails_ops/authorization_backend/can_can_can.rb +3 -1
  16. data/lib/rails_ops/controller_mixin.rb +1 -1
  17. data/lib/rails_ops/hookup/dsl_validator.rb +2 -1
  18. data/lib/rails_ops/hookup.rb +1 -1
  19. data/lib/rails_ops/mixins/authorization.rb +2 -2
  20. data/lib/rails_ops/mixins/model/nesting.rb +22 -23
  21. data/lib/rails_ops/mixins/policies.rb +7 -7
  22. data/lib/rails_ops/mixins/routes.rb +1 -1
  23. data/lib/rails_ops/model_mixins/marshalling.rb +1 -1
  24. data/lib/rails_ops/operation/model/load.rb +2 -4
  25. data/lib/rails_ops/operation/model/update.rb +2 -2
  26. data/lib/rails_ops/operation/model.rb +1 -1
  27. data/lib/rails_ops/operation.rb +7 -4
  28. data/lib/rails_ops/profiler/node.rb +1 -1
  29. data/lib/rails_ops/profiler.rb +1 -1
  30. data/lib/rails_ops.rb +43 -43
  31. data/rails_ops.gemspec +5 -5
  32. data/test/dummy/bin/bundle +1 -1
  33. data/test/dummy/bin/setup +1 -1
  34. data/test/dummy/bin/update +1 -1
  35. data/test/dummy/bin/yarn +5 -7
  36. data/test/dummy/config/environments/production.rb +1 -1
  37. data/test/dummy/config/spring.rb +2 -2
  38. data/test/test_helper.rb +5 -5
  39. data/test/unit/rails_ops/generators/operation_generator_test.rb +108 -12
  40. data/test/unit/rails_ops/mixins/model/deep_nesting_test.rb +69 -10
  41. data/test/unit/rails_ops/mixins/param_authorization_test.rb +3 -3
  42. data/test/unit/rails_ops/mixins/policies_test.rb +2 -2
  43. data/test/unit/rails_ops/operation/update_auth_test.rb +2 -0
  44. data/test/unit/rails_ops/operation/update_lazy_auth_test.rb +1 -0
  45. data/test/unit/rails_ops/operation_test.rb +1 -1
  46. metadata +12 -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: dcb574a4ebd4148a9db8bc6ae9e129b015140175352dccb01b0f9eb6e53a4afd
4
+ data.tar.gz: 31322cd290160be87eee75fe5ca3604d7611344f4b77faff2681364a34b166f5
5
5
  SHA512:
6
- metadata.gz: 4ce25936523ca89e92e1aad1fbb0e884bd6bcd230afd1faa8e106a48f0f853d1305b1e6621063bc2b538e0a6e1e4ca1d8c8e395356489d552d764baf29410713
7
- data.tar.gz: 970ffa94554885d4bcd9a2351a5b413d245f5f3b1ea7900d0220d1fe7e0d52fa98389025f61a29f7c0b300955741e09d8321502697d4a18235eaf97729952b49
6
+ metadata.gz: 81e0839e7d210cc6011868a3ea69bf5dd2714aabe96137ee6109468a00ff69400ccfe6fcc5a52a93c772dad15e3638bd0944ffc073f18f010ebd33f648cae1b1
7
+ data.tar.gz: 1bbc3608339025bd703a5a74a192056f462a5fb756f76531f570cedf754b0d5009d2e69319afc940a1dfc57e38a67fbf1a4fae8f62fb702fc35cb378adcc7825
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,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.3 (2023-03-27)
4
+
5
+ * Extend the `operation` generator to accept additional flags to skip the
6
+ generation of certain actions. In particular, the `--skip-index`,
7
+ `--skip-show`, `--skip-create`, `--skip-update` and `--skip-destroy` flags
8
+ were added.
9
+
10
+ Internal reference: `#111041`.
11
+
12
+ ## 1.4.2 (2023-03-27)
13
+
14
+ * Update the `operation` generator such that it complies with the naming
15
+ conventions laid out in [Placing and naming
16
+ operations](https://github.com/sitrox/rails_ops#placing-and-naming-operations).
17
+ The path were the operations reside and the validation schema key are now
18
+ generated in singular.
19
+
20
+ Internal reference: `#111055`.
3
21
 
4
22
  ## 1.4.1 (2023-02-21)
5
23
 
data/README.md CHANGED
@@ -70,11 +70,11 @@ Requirements & Installation
70
70
 
71
71
  # Define the Operations module
72
72
  module Operations; end
73
-
73
+
74
74
  # Add the folder to the autoloader, but namespaced
75
75
  loader = Rails.autoloaders.main
76
76
  loader.push_dir(app_operations, namespace: Operations)
77
-
77
+
78
78
  # Add the folder to the watched directories (for re-loading in development)
79
79
  Rails.application.config.watchable_dirs.merge!({
80
80
  app_operations => [:rb]
@@ -1674,6 +1674,16 @@ flags:
1674
1674
 
1675
1675
  Or if you want to skip them all: `--only-operations`.
1676
1676
 
1677
+ If you want to skip a certain action, you can do so using the flags:
1678
+ * `--skip-index`
1679
+ * `--skip-show`
1680
+ * `--skip-create`
1681
+ * `--skip-update`
1682
+ * `--skip-destroy`
1683
+
1684
+ This will skip the creation of the respective route, controller action, view file and the operation itself.
1685
+ For `--skip-create`, the `new` action will also be skipped and for `--skip-update`, the `edit` action will be skipped respectively.
1686
+
1677
1687
  You can also add a module as a namespace, all generated files will be put in
1678
1688
  the proper subfolders and modules by using the `--module` option.
1679
1689
 
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.3
@@ -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: '../'
@@ -1,16 +1,45 @@
1
1
  class OperationGenerator < Rails::Generators::NamedBase
2
2
  source_root File.expand_path('templates', __dir__)
3
3
 
4
+ class_option :skip_index, type: :boolean, desc: "Don't create the index route / view / controller action"
5
+ class_option :skip_show, type: :boolean, desc: "Don't create the show route / view / controller action and the load operation"
6
+ class_option :skip_create, type: :boolean, desc: "Don't create the new / create route / view / controller action and the create operation"
7
+ class_option :skip_update, type: :boolean, desc: "Don't create the edit / update route / view / controller action and the update operation"
8
+ class_option :skip_destroy, type: :boolean, desc: "Don't create the destroy route / view / controller action and the destroy operation"
4
9
  class_option :skip_controller, type: :boolean, desc: "Don't add a controller."
5
10
  class_option :skip_views, type: :boolean, desc: "Don't add the views."
6
11
  class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
7
12
  class_option :only_operations, type: :boolean, desc: 'Only add the operations. This is equal to specifying --skip-controller --skip-routes --skip-views'
8
13
  class_option :module, type: :string, desc: 'Add the operations in a module, e.g. "Admin" results in namespacing everything in the Admin module'
9
14
 
15
+ def excluded_actions
16
+ @excluded_actions = []
17
+
18
+ if options[:skip_index]
19
+ @excluded_actions += %i[index]
20
+ end
21
+
22
+ if options[:skip_show]
23
+ @excluded_actions += %i[show]
24
+ end
25
+
26
+ if options[:skip_create]
27
+ @excluded_actions += %i[new create]
28
+ end
29
+
30
+ if options[:skip_update]
31
+ @excluded_actions += %i[edit update]
32
+ end
33
+
34
+ if options[:skip_destroy]
35
+ @excluded_actions += %i[destroy]
36
+ end
37
+ end
38
+
10
39
  def add_operations
11
40
  @class_name = name.classify
12
- @underscored_name = name.underscore
13
- @underscored_pluralized_name = name.underscore.pluralize
41
+ @underscored_name = @class_name.underscore
42
+ @underscored_pluralized_name = @class_name.underscore.pluralize
14
43
 
15
44
  operations_path = 'app/operations/'
16
45
 
@@ -23,10 +52,18 @@ class OperationGenerator < Rails::Generators::NamedBase
23
52
 
24
53
  operations_path += @underscored_name.to_s
25
54
 
26
- template 'load.erb', "#{operations_path}/load.rb"
27
- template 'create.erb', "#{operations_path}/create.rb"
28
- template 'update.erb', "#{operations_path}/update.rb"
29
- template 'destroy.erb', "#{operations_path}/destroy.rb"
55
+ if !@excluded_actions.include?(:show)
56
+ template 'load.erb', "#{operations_path}/load.rb"
57
+ end
58
+ if !@excluded_actions.include?(:create)
59
+ template 'create.erb', "#{operations_path}/create.rb"
60
+ end
61
+ if !@excluded_actions.include?(:update)
62
+ template 'update.erb', "#{operations_path}/update.rb"
63
+ end
64
+ if !@excluded_actions.include?(:destroy)
65
+ template 'destroy.erb', "#{operations_path}/destroy.rb"
66
+ end
30
67
  end
31
68
 
32
69
  def add_controller
@@ -39,7 +76,7 @@ class OperationGenerator < Rails::Generators::NamedBase
39
76
  controller_file_path += "#{@underscored_pluralized_name}_controller.rb"
40
77
  @controller_name = "#{@class_name.pluralize}Controller"
41
78
 
42
- template 'controller.erb', controller_file_path
79
+ template 'controller_wrapper.erb', controller_file_path
43
80
  end
44
81
 
45
82
  def add_views
@@ -51,7 +88,13 @@ class OperationGenerator < Rails::Generators::NamedBase
51
88
  end
52
89
  views_folder += @underscored_pluralized_name.to_s
53
90
 
54
- %w(index show new edit).each do |view|
91
+ actions = %w[index show new edit]
92
+
93
+ @excluded_actions.each do |a|
94
+ actions.delete(a.to_s)
95
+ end
96
+
97
+ actions.each do |view|
55
98
  template 'view.erb', "#{views_folder}/#{view}.html.haml"
56
99
  end
57
100
  end
@@ -59,6 +102,10 @@ class OperationGenerator < Rails::Generators::NamedBase
59
102
  def add_routes
60
103
  return if options[:skip_routes] || options[:only_operations]
61
104
 
62
- route "resources :#{@underscored_pluralized_name}"
105
+ if @excluded_actions.empty?
106
+ route "resources :#{@underscored_pluralized_name}"
107
+ else
108
+ route "resources :#{@underscored_pluralized_name}, except: #{@excluded_actions}"
109
+ end
63
110
  end
64
111
  end
@@ -1,56 +1,67 @@
1
- <%
2
- controller_code = <<-RUBY
3
- class #{@controller_name} < ApplicationController
1
+ class <%=@controller_name%> < ApplicationController
2
+ <% first=true -%>
3
+ <% if !@excluded_actions&.include?(:index) -%>
4
+ <% first=false -%>
4
5
  def index; end
6
+ <% end -%>
7
+ <% if !@excluded_actions&.include?(:show) -%>
8
+ <% if first -%>
9
+ <% first=false -%>
10
+ <% else -%>
5
11
 
12
+ <% end -%>
6
13
  def show
7
- op Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Load
14
+ op Operations<%="::#{@module_name}" if @module_name.present?%>::<%=@class_name%>::Load
8
15
  end
16
+ <% end -%>
17
+ <% if !@excluded_actions&.include?(:create) -%>
18
+ <% if first -%>
19
+ <% first=false -%>
20
+ <% else -%>
9
21
 
22
+ <% end -%>
10
23
  def new
11
- op Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Create
24
+ op Operations<%="::#{@module_name}" if @module_name.present?%>::<%=@class_name%>::Create
12
25
  end
13
26
 
14
27
  def create
15
- if run Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Create
28
+ if run Operations<%="::#{@module_name}" if @module_name.present?%>::<%=@class_name%>::Create
16
29
  # handle successful case
17
30
  else
18
31
  # handle error case
19
32
  end
20
33
  end
34
+ <% end -%>
35
+ <% if !@excluded_actions&.include?(:update) -%>
36
+ <% if first -%>
37
+ <% first=false -%>
38
+ <% else -%>
21
39
 
40
+ <% end -%>
22
41
  def edit
23
- op Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Update
42
+ op Operations<%="::#{@module_name}" if @module_name.present?%>::<%=@class_name%>::Update
24
43
  end
25
44
 
26
45
  def update
27
- if run Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Update
46
+ if run Operations<%="::#{@module_name}" if @module_name.present?%>::<%=@class_name%>::Update
28
47
  # handle successful case
29
48
  else
30
49
  # handle error case
31
50
  end
32
51
  end
52
+ <% end -%>
53
+ <% if !@excluded_actions&.include?(:destroy) -%>
54
+ <% if first -%>
55
+ <% first=false -%>
56
+ <% else -%>
33
57
 
58
+ <% end -%>
34
59
  def destroy
35
- if run Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Destroy
60
+ if run Operations<%="::#{@module_name}" if @module_name.present?%>::<%=@class_name%>::Destroy
36
61
  # handle successful case
37
62
  else
38
63
  # handle error case
39
64
  end
40
65
  end
41
- end
42
- RUBY
43
- -%>
44
- <% if @module_name.present? -%>
45
- module <%= @module_name %>
46
- <% controller_code.split("\n").each do |line| -%>
47
- <% if line.blank? -%>
48
-
49
- <% else -%>
50
- <%= line %>
51
- <% end -%>
52
66
  <% end -%>
53
67
  end
54
- <% else -%>
55
- <%= controller_code -%>
56
- <% end -%>
@@ -0,0 +1,14 @@
1
+ <% controller_template = ERB.new(File.read(File.join(File.dirname(__FILE__), '/controller.erb')), trim_mode: '-').result(binding).strip -%>
2
+ <% if @module_name.present? -%>
3
+ module <%= @module_name %>
4
+ <% controller_template.split("\n").each do |line| -%>
5
+ <% if line.blank? -%>
6
+
7
+ <% else -%>
8
+ <%= line %>
9
+ <% end -%>
10
+ <% end -%>
11
+ end
12
+ <% else -%>
13
+ <%= controller_template %>
14
+ <% 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.