Skip to content

Commit 7c80f63

Browse files
committed
Rubocop
1 parent 036c205 commit 7c80f63

37 files changed

+66
-92
lines changed

.rubocop.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
AllCops:
1919
TargetRubyVersion: 3.2
2020
TargetRailsVersion: 7.1
21+
SuggestExtensions: false
2122

2223
NewCops: enable
2324

2425
Exclude:
2526
- '**/vendor/**/*'
2627

27-
plugins:
28-
- rubocop-performance
29-
3028
# Rules for CustomWorkflows
3129
Metrics/BlockLength:
3230
Enabled: false

app/models/custom_workflow.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def self.log_message(str, object)
7171
Rails.logger.info "#{str} for #{object.class} (##{object.id}) \"#{object}\""
7272
end
7373

74-
def self.run_shared_code(object)
74+
def self.run_shared_code?(object)
7575
# Due to DB migration
7676
if CustomWorkflow.table_exists? && CustomWorkflow.active.exists?(observable: :shared)
7777
log_message '= Running shared code', object
@@ -86,7 +86,7 @@ def self.run_shared_code(object)
8686
true
8787
end
8888

89-
def self.run_custom_workflows(observable, object, event)
89+
def self.run_custom_workflows?(observable, object, event)
9090
if CustomWorkflow.table_exists? # Due to DB migration
9191
workflows = CustomWorkflow.active.where(observable: observable)
9292
if PROJECT_OBSERVABLES.include? observable
@@ -153,12 +153,12 @@ def validate_scripts_presence
153153
def validate_syntax
154154
case observable.to_sym
155155
when :shared
156-
CustomWorkflow.run_shared_code self
156+
CustomWorkflow.run_shared_code? self
157157
validate_syntax_for self, :shared_code
158158
when *SINGLE_OBSERVABLES
159159
object = observable.camelize.constantize.new
160160
object.send :instance_variable_set, "@#{observable}", object # compatibility with 0.0.1
161-
CustomWorkflow.run_shared_code object
161+
CustomWorkflow.run_shared_code? object
162162
%i[before_save after_save before_destroy after_destroy].each { |field| validate_syntax_for object, field }
163163
when *COLLECTION_OBSERVABLES
164164
object = nil
@@ -180,7 +180,7 @@ def validate_syntax
180180
object.send :instance_variable_set, :@attachment, Attachment.new
181181
object.send :instance_variable_set, :@page, object
182182
end
183-
CustomWorkflow.run_shared_code object
183+
CustomWorkflow.run_shared_code? object
184184
%i[before_add after_add before_remove after_remove].each { |field| validate_syntax_for object, field }
185185
end
186186
end

lib/redmine_custom_workflows/patches/models/attachment_patch.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def self.prepended(base)
4242
def before_save_custom_workflows
4343
@attachment = self
4444
@saved_attributes = attributes.dup
45-
CustomWorkflow.run_shared_code self
46-
CustomWorkflow.run_custom_workflows :attachment, self, :before_save
45+
CustomWorkflow.run_shared_code? self
46+
CustomWorkflow.run_custom_workflows? :attachment, self, :before_save
4747
throw :abort if errors.any?
4848

4949
errors.empty? && (@saved_attributes == attributes || valid?)
@@ -52,16 +52,16 @@ def before_save_custom_workflows
5252
end
5353

5454
def after_save_custom_workflows
55-
CustomWorkflow.run_custom_workflows :attachment, self, :after_save
55+
CustomWorkflow.run_custom_workflows? :attachment, self, :after_save
5656
end
5757

5858
def before_destroy_custom_workflows
59-
res = CustomWorkflow.run_custom_workflows :attachment, self, :before_destroy
59+
res = CustomWorkflow.run_custom_workflows? :attachment, self, :before_destroy
6060
throw :abort if res == false
6161
end
6262

6363
def after_destroy_custom_workflows
64-
CustomWorkflow.run_custom_workflows :attachment, self, :after_destroy
64+
CustomWorkflow.run_custom_workflows? :attachment, self, :after_destroy
6565
end
6666
end
6767
end

lib/redmine_custom_workflows/patches/models/group_patch.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def self.prepended(base)
4747
def self.users_callback(event, group, user)
4848
group.instance_variable_set :@group, group
4949
group.instance_variable_set :@user, user
50-
CustomWorkflow.run_shared_code(group) if event.to_s.starts_with? 'before_'
51-
CustomWorkflow.run_custom_workflows :group_users, group, event
50+
CustomWorkflow.run_shared_code?(group) if event.to_s.starts_with? 'before_'
51+
CustomWorkflow.run_custom_workflows? :group_users, group, event
5252
end
5353

5454
%i[before_add before_remove after_add after_remove].each do |observable|
@@ -62,8 +62,8 @@ def self.users_callback(event, group, user)
6262
def before_save_custom_workflows
6363
@group = self
6464
@saved_attributes = attributes.dup
65-
CustomWorkflow.run_shared_code self
66-
CustomWorkflow.run_custom_workflows :group, self, :before_save
65+
CustomWorkflow.run_shared_code? self
66+
CustomWorkflow.run_custom_workflows? :group, self, :before_save
6767
throw :abort if errors.any?
6868

6969
errors.empty? && (@saved_attributes == attributes || valid?)
@@ -72,16 +72,16 @@ def before_save_custom_workflows
7272
end
7373

7474
def after_save_custom_workflows
75-
CustomWorkflow.run_custom_workflows :group, self, :after_save
75+
CustomWorkflow.run_custom_workflows? :group, self, :after_save
7676
end
7777

7878
def before_destroy_custom_workflows
79-
res = CustomWorkflow.run_custom_workflows :group, self, :before_destroy
79+
res = CustomWorkflow.run_custom_workflows? :group, self, :before_destroy
8080
throw :abort if res == false
8181
end
8282

8383
def after_destroy_custom_workflows
84-
CustomWorkflow.run_custom_workflows :group, self, :after_destroy
84+
CustomWorkflow.run_custom_workflows? :group, self, :after_destroy
8585
end
8686
end
8787
end

lib/redmine_custom_workflows/patches/models/issue_patch.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def self.prepended(base)
4646
def self.attachments_callback(event, issue, attachment)
4747
issue.instance_variable_set :@issue, issue
4848
issue.instance_variable_set :@attachment, attachment
49-
CustomWorkflow.run_shared_code(issue) if event.to_s.starts_with? 'before_'
50-
CustomWorkflow.run_custom_workflows :issue_attachments, issue, event
49+
CustomWorkflow.run_shared_code?(issue) if event.to_s.starts_with? 'before_'
50+
CustomWorkflow.run_custom_workflows? :issue_attachments, issue, event
5151
end
5252

5353
%i[before_add before_remove after_add after_remove].each do |observable|
@@ -76,8 +76,8 @@ def validate_status
7676
def before_save_custom_workflows
7777
@issue = self
7878
@saved_attributes = attributes.dup
79-
CustomWorkflow.run_shared_code self
80-
CustomWorkflow.run_custom_workflows :issue, self, :before_save
79+
CustomWorkflow.run_shared_code? self
80+
CustomWorkflow.run_custom_workflows? :issue, self, :before_save
8181
throw :abort if errors.any?
8282

8383
errors.empty? && (@saved_attributes == attributes || valid?)
@@ -86,16 +86,16 @@ def before_save_custom_workflows
8686
end
8787

8888
def after_save_custom_workflows
89-
CustomWorkflow.run_custom_workflows :issue, self, :after_save
89+
CustomWorkflow.run_custom_workflows? :issue, self, :after_save
9090
end
9191

9292
def before_destroy_custom_workflows
93-
res = CustomWorkflow.run_custom_workflows(:issue, self, :before_destroy)
93+
res = CustomWorkflow.run_custom_workflows?(:issue, self, :before_destroy)
9494
throw :abort if res == false
9595
end
9696

9797
def after_destroy_custom_workflows
98-
CustomWorkflow.run_custom_workflows :issue, self, :after_destroy
98+
CustomWorkflow.run_custom_workflows? :issue, self, :after_destroy
9999
end
100100
end
101101
end

lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,25 @@ def to_s(issue = nil)
6060
def before_save_custom_workflows
6161
@issue_relation = self
6262
@saved_attributes = attributes.dup
63-
CustomWorkflow.run_shared_code self
64-
CustomWorkflow.run_custom_workflows :issue_relation, self, :before_save
63+
CustomWorkflow.run_shared_code? self
64+
CustomWorkflow.run_custom_workflows? :issue_relation, self, :before_save
6565
throw :abort if errors.any?
6666
errors.empty? && (@saved_attributes == attributes || valid?)
6767
ensure
6868
@saved_attributes = nil
6969
end
7070

7171
def after_save_custom_workflows
72-
CustomWorkflow.run_custom_workflows :issue_relation, self, :after_save
72+
CustomWorkflow.run_custom_workflows? :issue_relation, self, :after_save
7373
end
7474

7575
def before_destroy_custom_workflows
76-
res = CustomWorkflow.run_custom_workflows :issue_relation, self, :before_destroy
76+
res = CustomWorkflow.run_custom_workflows? :issue_relation, self, :before_destroy
7777
throw :abort if res == false
7878
end
7979

8080
def after_destroy_custom_workflows
81-
CustomWorkflow.run_custom_workflows :issue_relation, self, :after_destroy
81+
CustomWorkflow.run_custom_workflows? :issue_relation, self, :after_destroy
8282
end
8383
end
8484
end

lib/redmine_custom_workflows/patches/models/member_patch.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def self.prepended(base)
4242
def before_save_custom_workflows
4343
@member = self
4444
@saved_attributes = attributes.dup
45-
CustomWorkflow.run_shared_code self
46-
CustomWorkflow.run_custom_workflows :member, self, :before_save
45+
CustomWorkflow.run_shared_code? self
46+
CustomWorkflow.run_custom_workflows? :member, self, :before_save
4747
throw :abort if errors.any?
4848

4949
errors.empty? && (@saved_attributes == attributes || valid?)
@@ -52,16 +52,16 @@ def before_save_custom_workflows
5252
end
5353

5454
def after_save_custom_workflows
55-
CustomWorkflow.run_custom_workflows :member, self, :after_save
55+
CustomWorkflow.run_custom_workflows? :member, self, :after_save
5656
end
5757

5858
def before_destroy_custom_workflows
59-
res = CustomWorkflow.run_custom_workflows :member, self, :before_destroy
59+
res = CustomWorkflow.run_custom_workflows? :member, self, :before_destroy
6060
throw :abort if res == false
6161
end
6262

6363
def after_destroy_custom_workflows
64-
CustomWorkflow.run_custom_workflows :member, self, :after_destroy
64+
CustomWorkflow.run_custom_workflows? :member, self, :after_destroy
6565
end
6666
end
6767
end

lib/redmine_custom_workflows/patches/models/project_patch.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def self.prepended(base)
5555
def self.attachments_callback(event, project, attachment)
5656
project.instance_variable_set(:@project, project)
5757
project.instance_variable_set(:@attachment, attachment)
58-
CustomWorkflow.run_shared_code(project) if event.to_s.starts_with? 'before_'
59-
CustomWorkflow.run_custom_workflows(:project_attachments, project, event)
58+
CustomWorkflow.run_shared_code?(project) if event.to_s.starts_with? 'before_'
59+
CustomWorkflow.run_custom_workflows?(:project_attachments, project, event)
6060
end
6161

6262
%i[before_add before_remove after_add after_remove].each do |observable|
@@ -70,8 +70,8 @@ def self.attachments_callback(event, project, attachment)
7070
def before_save_custom_workflows
7171
@project = self
7272
@saved_attributes = attributes.dup
73-
CustomWorkflow.run_shared_code self
74-
CustomWorkflow.run_custom_workflows :project, self, :before_save
73+
CustomWorkflow.run_shared_code? self
74+
CustomWorkflow.run_custom_workflows? :project, self, :before_save
7575
throw :abort if errors.any?
7676

7777
errors.empty? && (@saved_attributes == attributes || valid?)
@@ -80,16 +80,16 @@ def before_save_custom_workflows
8080
end
8181

8282
def after_save_custom_workflows
83-
CustomWorkflow.run_custom_workflows :project, self, :after_save
83+
CustomWorkflow.run_custom_workflows? :project, self, :after_save
8484
end
8585

8686
def before_destroy_custom_workflows
87-
res = CustomWorkflow.run_custom_workflows :project, self, :before_destroy
87+
res = CustomWorkflow.run_custom_workflows? :project, self, :before_destroy
8888
throw :abort if res == false
8989
end
9090

9191
def after_destroy_custom_workflows
92-
CustomWorkflow.run_custom_workflows :project, self, :after_destroy
92+
CustomWorkflow.run_custom_workflows? :project, self, :after_destroy
9393
end
9494
end
9595
end

lib/redmine_custom_workflows/patches/models/time_entry_patch.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def self.prepended(base)
4242
def before_save_custom_workflows
4343
@time_entry = self
4444
@saved_attributes = attributes.dup
45-
CustomWorkflow.run_shared_code(self)
46-
CustomWorkflow.run_custom_workflows(:time_entry, self, :before_save)
45+
CustomWorkflow.run_shared_code?(self)
46+
CustomWorkflow.run_custom_workflows?(:time_entry, self, :before_save)
4747
throw :abort if errors.any?
4848

4949
errors.empty? && (@saved_attributes == attributes || valid?)
@@ -52,16 +52,16 @@ def before_save_custom_workflows
5252
end
5353

5454
def after_save_custom_workflows
55-
CustomWorkflow.run_custom_workflows :time_entry, self, :after_save
55+
CustomWorkflow.run_custom_workflows? :time_entry, self, :after_save
5656
end
5757

5858
def before_destroy_custom_workflows
59-
res = CustomWorkflow.run_custom_workflows :time_entry, self, :before_destroy
59+
res = CustomWorkflow.run_custom_workflows? :time_entry, self, :before_destroy
6060
throw :abort if res == false
6161
end
6262

6363
def after_destroy_custom_workflows
64-
CustomWorkflow.run_custom_workflows :time_entry, self, :after_destroy
64+
CustomWorkflow.run_custom_workflows? :time_entry, self, :after_destroy
6565
end
6666
end
6767
end

lib/redmine_custom_workflows/patches/models/user_patch.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def self.prepended(base)
4242
def before_save_custom_workflows
4343
@user = self
4444
@saved_attributes = attributes.dup
45-
CustomWorkflow.run_shared_code self
46-
CustomWorkflow.run_custom_workflows :user, self, :before_save
45+
CustomWorkflow.run_shared_code? self
46+
CustomWorkflow.run_custom_workflows? :user, self, :before_save
4747
throw :abort if errors.any?
4848

4949
errors.empty? && (@saved_attributes == attributes || valid?)
@@ -52,16 +52,16 @@ def before_save_custom_workflows
5252
end
5353

5454
def after_save_custom_workflows
55-
CustomWorkflow.run_custom_workflows :user, self, :after_save
55+
CustomWorkflow.run_custom_workflows? :user, self, :after_save
5656
end
5757

5858
def before_destroy_custom_workflows
59-
res = CustomWorkflow.run_custom_workflows :user, self, :before_destroy
59+
res = CustomWorkflow.run_custom_workflows? :user, self, :before_destroy
6060
throw :abort if res == false
6161
end
6262

6363
def after_destroy_custom_workflows
64-
CustomWorkflow.run_custom_workflows :user, self, :after_destroy
64+
CustomWorkflow.run_custom_workflows? :user, self, :after_destroy
6565
end
6666
end
6767
end

0 commit comments

Comments
 (0)