Module: Componentize

Extended by:
ActiveSupport::Concern
Included in:
AbilityHost, Course::ControllerComponentHost, Course::ModelComponentHost
Defined in:
lib/autoload/componentize.rb

Overview

Allows associating classes with other classes. This can form a nesting hierarchy. This is also used in Coursemology to associate components that a course can have enabled.

In Development mode, classes are not eager loaded. Component hosts then do not know which components have been implemented. Call #eager_load_components to load all components within a given path.

Examples:

Declare that a class can host other components.

class Course
  include Componentize
end

Declare that the Announcements class is a component belonging to a Course.

class Announcements
  include Course::Component
end

Defined Under Namespace

Modules: Component, ComponentHost

Class Method Summary collapse

Class Method Details

.become_component_host(host) ⇒ Object

Extends the given host with methods needed to host other classes.

Parameters:

  • host (Class)

    The host to convert into a host.


28
29
30
31
32
33
34
35
# File 'lib/autoload/componentize.rb', line 28

def self.become_component_host(host)
  return if host.include?(ComponentHost)
  host.const_set(:Component, base_component_for_host(host))

  host.class_eval do
    include ComponentHost
  end
end