Module: EffectiveCpdUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_cpd_user.rb
Overview
EffectiveCpdUser
Mark your user model with effective_cpd_user to get a few helpers And user specific point required scores
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
-
#build_cpd_statement(cpd_cycle:) ⇒ Object
Find or build.
-
#build_cpd_target(cpd_cycle:) ⇒ Object
Find or build.
-
#build_cpd_targets ⇒ Object
For the form.
- #cpd_audit_cpd_required? ⇒ Boolean
- #cpd_audit_reviewer? ⇒ Boolean
- #cpd_statement(cpd_cycle:) ⇒ Object
-
#cpd_target(cpd_cycle:) ⇒ Object
Dont use IDs here.
-
#cpd_target_score(cpd_cycle:) ⇒ Object
Requires for this user.
- #cpd_target_score_required_to_submit?(cpd_cycle:) ⇒ Boolean
-
#default_cpd_target_score(cpd_cycle:) ⇒ Object
Required for this user category without the targets Otherwise calculate default by membership category.
Instance Method Details
#build_cpd_statement(cpd_cycle:) ⇒ Object
Find or build
87 88 89 90 |
# File 'app/models/concerns/effective_cpd_user.rb', line 87 def build_cpd_statement(cpd_cycle:) raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?) cpd_statement(cpd_cycle: cpd_cycle) || cpd_statements.build(cpd_cycle: cpd_cycle) end |
#build_cpd_target(cpd_cycle:) ⇒ Object
Find or build
99 100 101 102 |
# File 'app/models/concerns/effective_cpd_user.rb', line 99 def build_cpd_target(cpd_cycle:) raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?) cpd_target(cpd_cycle: cpd_cycle) || cpd_targets.build(cpd_cycle: cpd_cycle) end |
#build_cpd_targets ⇒ Object
For the form
105 106 107 108 109 110 |
# File 'app/models/concerns/effective_cpd_user.rb', line 105 def build_cpd_targets Effective::CpdCycle.sorted.all.each do |cpd_cycle| cpd_target(cpd_cycle: cpd_cycle) || cpd_targets.new(cpd_cycle: cpd_cycle) end cpd_targets.sort_by(&:cpd_cycle_id).reverse end |
#cpd_audit_cpd_required? ⇒ Boolean
73 74 75 |
# File 'app/models/concerns/effective_cpd_user.rb', line 73 def cpd_audit_cpd_required? true end |
#cpd_audit_reviewer? ⇒ Boolean
77 78 79 |
# File 'app/models/concerns/effective_cpd_user.rb', line 77 def cpd_audit_reviewer? roles.include?(:cpd_audit_reviewer) end |
#cpd_statement(cpd_cycle:) ⇒ Object
81 82 83 84 |
# File 'app/models/concerns/effective_cpd_user.rb', line 81 def cpd_statement(cpd_cycle:) raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?) cpd_statements.find { |cpd_statement| cpd_statement.cpd_cycle_id == cpd_cycle.id } end |
#cpd_target(cpd_cycle:) ⇒ Object
Dont use IDs here
93 94 95 96 |
# File 'app/models/concerns/effective_cpd_user.rb', line 93 def cpd_target(cpd_cycle:) raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?) cpd_targets.find { |cpd_target| cpd_target.cpd_cycle == cpd_cycle } end |
#cpd_target_score(cpd_cycle:) ⇒ Object
Requires for this user
47 48 49 50 51 52 |
# File 'app/models/concerns/effective_cpd_user.rb', line 47 def cpd_target_score(cpd_cycle:) target = cpd_target(cpd_cycle: cpd_cycle) return target.score if target&.score.present? default_cpd_target_score(cpd_cycle: cpd_cycle) end |
#cpd_target_score_required_to_submit?(cpd_cycle:) ⇒ Boolean
66 67 68 69 70 71 |
# File 'app/models/concerns/effective_cpd_user.rb', line 66 def cpd_target_score_required_to_submit?(cpd_cycle:) target = cpd_target(cpd_cycle: cpd_cycle) return target.required_to_submit? unless target&.required_to_submit.nil? cpd_cycle.required_to_submit? end |
#default_cpd_target_score(cpd_cycle:) ⇒ Object
Required for this user category without the targets Otherwise calculate default by membership category
56 57 58 59 60 61 62 63 64 |
# File 'app/models/concerns/effective_cpd_user.rb', line 56 def default_cpd_target_score(cpd_cycle:) if self.class.try(:effective_memberships_user?) category = membership_categories_on(cpd_cycle.start_at)&.first if cpd_cycle.start_at.present? category ||= membership_categories_on(cpd_cycle.end_at)&.first if cpd_cycle.end_at.present? category ||= membership&.categories&.first category&.cpd_target_score(cpd_cycle: cpd_cycle) end end |