Module: EffectiveCpdBulkAudit
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_cpd_bulk_audit.rb
Overview
EffectiveCpdBulkAudit
Mark your owner model with effective_cpd_bulk_audit to get all the includes
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary
collapse
Instance Method Details
#build_cpd_audit(auditee, reviewers) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'app/models/concerns/effective_cpd_bulk_audit.rb', line 121
def build_cpd_audit(auditee, reviewers)
raise('expected auditee cpd user') unless auditee.class.respond_to?(:effective_cpd_user?)
reviewers = Array(reviewers)
raise('expected audit reviewers') unless reviewers.all? { |reviewer| reviewer.try(:cpd_audit_reviewer?) }
cpd_audit = EffectiveCpd.CpdAudit.new(
cpd_audit_level: cpd_audit_level,
email_form_skip: email_form_skip?,
user: auditee,
notification_date: notification_date
)
reviewers.each do |reviewer|
cpd_audit.cpd_audit_reviews.build(
cpd_audit_level: cpd_audit_level,
email_form_skip: email_form_skip?,
user: reviewer
)
end
cpd_audit
end
|
#cpd_audit_reviewers ⇒ Object
94
95
96
|
# File 'app/models/concerns/effective_cpd_bulk_audit.rb', line 94
def cpd_audit_reviewers
cpd_user_scope.send(EffectiveCpd.audit_reviewer_user_scope)
end
|
#cpd_auditees ⇒ Object
90
91
92
|
# File 'app/models/concerns/effective_cpd_bulk_audit.rb', line 90
def cpd_auditees
cpd_user_scope.send(EffectiveCpd.auditee_user_scope)
end
|
#cpd_user_scope ⇒ Object
86
87
88
|
# File 'app/models/concerns/effective_cpd_bulk_audit.rb', line 86
def cpd_user_scope
cpd_user_class_name.constantize.all if cpd_user_class_name.present?
end
|
#create_audits! ⇒ Object
Called by Effective::CpdBulkAuditJob
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'app/models/concerns/effective_cpd_bulk_audit.rb', line 105
def create_audits!
save!
@auditees = cpd_auditees.reorder('RANDOM()').limit(audits)
@reviewers = cpd_audit_reviewers.reorder('RANDOM()').limit(audits).to_a
@auditees.each do |auditee|
reviewers = audit_reviewers_per_audit.times.map { next_audit_reviewer() }
cpd_audit = build_cpd_audit(auditee, reviewers)
cpd_audit.save!
end
true
end
|
#create_bulk_audit_job! ⇒ Object
98
99
100
101
102
|
# File 'app/models/concerns/effective_cpd_bulk_audit.rb', line 98
def create_bulk_audit_job!
raise('must be persisted') unless persisted?
Effective::CpdBulkAuditJob.perform_later(id)
end
|
#next_audit_reviewer ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
|
# File 'app/models/concerns/effective_cpd_bulk_audit.rb', line 146
def next_audit_reviewer
raise('expected @audit_reviewers to be set') unless @reviewers
@reviewers_index ||= -1
@reviewers_index += 1
@reviewers_index = 0 if @reviewers_index >= @reviewers.length
@reviewers[@reviewers_index]
end
|
#to_s ⇒ Object
82
83
84
|
# File 'app/models/concerns/effective_cpd_bulk_audit.rb', line 82
def to_s
model_name.human
end
|