Module: Course::Settings::LessonPlanSettingsConcern

Extended by:
ActiveSupport::Concern
Included in:
SurveyComponent, VideosComponent
Defined in:
app/models/concerns/course/settings/lesson_plan_settings_concern.rb

Overview

This concern provides common defaults for querying and persisting lesson plan item settings for a course component. It abstracts out common code for components which only need their items fully enabled or disabled in the lesson plan.

For more complicated settings, look at how assessment lesson plan settings are implemented.

The lesson plan item settings for the given component is assumed to be stored in the following shape in course.settings:

{ course_component_key: { lesson_plan_items: { enabled: true, visible: false, } } }

To use this concern:

  • Include the concern in the settings model for the component.
  • Implement #lesson_plan_setting_items if additional attributes are needed in the hash.

Instance Method Summary collapse

Instance Method Details

#lesson_plan_item_settingsHash

A hash of concrete lesson plan settings for the component. This is used by Course::Settings::LessonPlanItems for the lesson plan settings page. See Course::Settings::LessonPlanItems#lesson_plan_item_settings for details of the hash shape.

Returns:

  • (Hash)

    Setting hash for a component.


33
34
35
36
37
38
39
40
41
# File 'app/models/concerns/course/settings/lesson_plan_settings_concern.rb', line 33

def lesson_plan_item_settings
  enabled_setting = settings.settings(:lesson_plan_items).enabled
  visible_setting = settings.settings(:lesson_plan_items).visible
  {
    component: key,
    enabled: enabled_setting.nil? ? true : enabled_setting,
    visible: visible_setting.nil? ? true : visible_setting
  }
end

#showable_in_lesson_plan?Boolean

Returns:

  • (Boolean)

56
57
58
# File 'app/models/concerns/course/settings/lesson_plan_settings_concern.rb', line 56

def showable_in_lesson_plan?
  settings.lesson_plan_items ? settings.lesson_plan_items['enabled'] : true
end

#update_lesson_plan_item_setting(attributes) ⇒ Object

Updates a lesson plan item setting.

Parameters:

  • attributes (Hash)

    New setting represented by a hash with 'component', 'enabled' and 'visible' keys, e.g. { 'component' => 'course_survey_component', 'enabled' => true, 'visible' => true }


48
49
50
51
52
53
54
# File 'app/models/concerns/course/settings/lesson_plan_settings_concern.rb', line 48

def update_lesson_plan_item_setting(attributes)
  settings.settings(:lesson_plan_items).enabled = ActiveRecord::Type::Boolean.new.
                                                  cast(attributes['enabled'])
  settings.settings(:lesson_plan_items).visible = ActiveRecord::Type::Boolean.new.
                                                  cast(attributes['visible'])
  true
end