Sha256: 8122b7449ad9081eceb634b6f9e35826f8194d736471b930f3996b8266422e73

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

# EffectiveCpdUser
#
# Mark your user model with effective_cpd_user to get a few helpers
# And user specific point required scores

module EffectiveCpdUser
  extend ActiveSupport::Concern

  module Base
    def effective_cpd_user
      include ::EffectiveCpdUser
    end
  end

  module ClassMethods
    def effective_cpd_user?; true; end
  end

  included do
    # App Scoped
    has_many :cpd_statements, -> { order(:cpd_cycle_id) }, inverse_of: :user, dependent: :destroy
    accepts_nested_attributes_for :cpd_statements, allow_destroy: true

    has_many :cpd_audits, -> { order(:id) }, inverse_of: :user
    has_many :cpd_audit_reviews, -> { order(:id) }, inverse_of: :user

    scope :cpd_audit_auditees, -> { without_role(:cpd_audit_reviewer) }
    scope :cpd_audit_reviewers, -> { with_role(:cpd_audit_reviewer) }
  end

  # This one will actually be enforced or displayed first
  def cpd_statement_required_score(cpd_statement)
    nil
  end

  # This one will be displayed on the sidebar if first one is nil
  # Won't actually block the submission
  def cpd_statement_targeted_score(cpd_statement)
    nil
  end

  def cpd_audit_cpd_required?
    true
  end

  def cpd_audit_reviewer?
    roles.include?(:cpd_audit_reviewer)
  end

  def cpd_statement(cpd_cycle:)
    raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cycle?)
    cpd_statements.find { |cpd_statement| cpd_statement.cpd_cycle_id == cpd_cycle.id }
  end

  # Find or build
  def build_cpd_statement(cpd_cycle:)
    raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cycle?)
    cpd_statement(cpd_cycle: cpd_cycle) || cpd_statements.build(cpd_cycle: cpd_cycle)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
effective_cpd-1.2.0 app/models/concerns/effective_cpd_user.rb
effective_cpd-1.1.3 app/models/concerns/effective_cpd_user.rb
effective_cpd-1.1.2 app/models/concerns/effective_cpd_user.rb
effective_cpd-1.1.1 app/models/concerns/effective_cpd_user.rb
effective_cpd-1.1.0 app/models/concerns/effective_cpd_user.rb