Module: Course::Settings::EmailSettingsConcern::ClassMethods

Defined in:
app/models/concerns/course/settings/email_settings_concern.rb

Instance Method Summary collapse

Instance Method Details

#component_classClass

Returns the class of the component which the setting model is associated with. This is used for querying settings when a component controller context is not available, e.g. when emails are sent out asynchronously.

Returns:

  • (Class)

    The component class

Raises:

  • (NotImplementedError)

44
45
46
# File 'app/models/concerns/course/settings/email_settings_concern.rb', line 44

def component_class
  raise NotImplementedError, 'Specify component class in settings model.'
end

#email_enabled?(course, key) ⇒ Boolean

Checks whether a type of email notification is enabled for a course.

Parameters:

  • course (Course)
  • key (Symbol)

    The email notification type

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)

52
53
54
55
56
57
# File 'app/models/concerns/course/settings/email_settings_concern.rb', line 52

def email_enabled?(course, key)
  raise ArgumentError, 'Invalid email key' unless valid_email_setting_key?(key)

  user_setting = course.settings(component_class.key, :emails, key).enabled
  user_setting.nil? ? email_setting_items[key][:enabled_by_default] : user_setting
end

#email_setting_itemsHash

Email setting items for the given component.

Returns:

  • (Hash)

    Each key represents an email setting. Each value is a Hash representing defaults for the email setting, e.g. { item_opening: { enabled_by_default: false }, item_closing: { enabled_by_default: true, days_in_advance: 2 }, }

Raises:

  • (NotImplementedError)

35
36
37
# File 'app/models/concerns/course/settings/email_settings_concern.rb', line 35

def email_setting_items
  raise NotImplementedError, 'Define component email settings in its settings model.'
end

#valid_email_setting_key?(key) ⇒ Boolean

Returns:

  • (Boolean)

59
60
61
# File 'app/models/concerns/course/settings/email_settings_concern.rb', line 59

def valid_email_setting_key?(key)
  email_setting_items.key?(key)
end