Class: Course::Settings::PanComponent

Inherits:
SimpleDelegator
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/course/settings/pan_component.rb

Overview

This serves as a base class for course settings models that are need settings from more than 1 course component.

Direct Known Subclasses

LessonPlanItems

Instance Method Summary collapse

Constructor Details

#initialize(components) ⇒ PanComponent

Returns a new instance of PanComponent


9
10
11
# File 'app/models/course/settings/pan_component.rb', line 9

def initialize(components)
  @components = components
end

Instance Method Details

#consolidate_settings_from_components(function_name) ⇒ Object

Calls the given function from the component settings which respond to the function. Each function returns settings stored in its respective component.

Parameters:

  • function_name (Symbol)

    The name of the function to be called.


17
18
19
20
21
22
# File 'app/models/course/settings/pan_component.rb', line 17

def consolidate_settings_from_components(function_name)
  all_settings = settings_interfaces_hash.values.map do |settings|
    settings.respond_to?(function_name) ? settings.send(function_name) : nil
  end
  all_settings.compact.flatten.sort_by { |item| item[:component] }
end

#update_setting_in_component(function_name, attributes) ⇒ Object

Calls the given function for updating a setting. The component key of the component which has the function should be passed in the attributes hash.

Parameters:

  • function_name (Symbol)

    The name of the function in the Course::Settings::Component class which will update the desired setting.

  • attributes (Hash)

31
32
33
34
35
# File 'app/models/course/settings/pan_component.rb', line 31

def update_setting_in_component(function_name, attributes)
  settings_interface = settings_interfaces_hash[attributes['component']]
  return false unless settings_interface
  settings_interface.send(function_name, attributes)
end