Module: Extensions::Conditional::ActiveRecord::Base::ConditionalInstanceMethods

Defined in:
lib/extensions/conditional/active_record/base.rb

Instance Method Summary collapse

Instance Method Details

#conditions_satisfied_by?(course_user) ⇒ Boolean

Check if all conditions are satisfied by the user.

Parameters:

  • course_user (CourseUser)

    The user that conditions are being checked on

Returns:

  • (Boolean)

    true if all conditions are met and false otherwise


32
33
34
# File 'lib/extensions/conditional/active_record/base.rb', line 32

def conditions_satisfied_by?(course_user)
  conditions.all? { |condition| condition.satisfied_by?(course_user) }
end

#duplicate_conditions(duplicator, other) ⇒ Object

Duplicate conditions if dependent objects have been duplicated


57
58
59
60
61
62
63
64
# File 'lib/extensions/conditional/active_record/base.rb', line 57

def duplicate_conditions(duplicator, other)
  conditions_to_duplicate = other.conditions.to_a.select do |condition|
    dependent_object = condition.actable.dependent_object
    duplicated = duplicator.duplicated?(condition.actable.dependent_object)
    duplicator.mode == :course ? (dependent_object.nil? || duplicated) : duplicated
  end.map(&:actable)
  conditions << duplicator.duplicate(conditions_to_duplicate).map(&:acting_as)
end

#permitted_for!(_course_user) ⇒ Object

Permit the conditional for the given course user.

Parameters:

  • _course_user (CourseUser)

    The course user in which the conditional is to unlock for

Raises:

  • (NotImplementedError)

39
40
41
# File 'lib/extensions/conditional/active_record/base.rb', line 39

def permitted_for!(_course_user)
  raise NotImplementedError, 'Subclasses must implement a permitted_for! method.'
end

#precluded_for!(_course_user) ⇒ Object

Preclude the conditional for the given course user.

Parameters:

  • _course_user (CourseUser)

    The course user in which the conditional is to lock for

Raises:

  • (NotImplementedError)

46
47
48
# File 'lib/extensions/conditional/active_record/base.rb', line 46

def precluded_for!(_course_user)
  raise NotImplementedError, 'Subclasses must implement a precluded_for! method.'
end

#satisfiable?Boolean

Whether the conditional is satisfiable?. e.g. Unpublished achievements should not never be satisfied and give to users.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

52
53
54
# File 'lib/extensions/conditional/active_record/base.rb', line 52

def satisfiable?
  raise NotImplementedError, 'Subclasses must implement a #satisfiable? method.'
end

#specific_conditionsObject


24
25
26
# File 'lib/extensions/conditional/active_record/base.rb', line 24

def specific_conditions
  conditions.map(&:actable)
end