module Sabrina::Plugin::Load

Allows to load plugins. Add load_plugins at the end of your class’s initialize call.

Attributes

plugins[R]

Public Class Methods

include_in(obj) click to toggle source

Exposes #append_features.

# File lib/sabrina/plugin/load.rb, line 8
def include_in(obj)
  append_features(obj) unless obj.include?(self)
end

Private Instance Methods

load_plugins() click to toggle source

Generates plugin instances. This should be called from the target class’s init.

@return [0]

# File lib/sabrina/plugin/load.rb, line 21
def load_plugins
  self.class.plugins.each do |plugin|
    n = plugin.short_name

    plugin.features.each do |f|
      feature_all_sym = f.to_sym
      feature_this_sym = "#{f}_#{n}"
      unless respond_to?(feature_all_sym)
        define_singleton_method(feature_all_sym, plugin.feature_all(f))
      end
      unless respond_to?(feature_this_sym)
        define_singleton_method(feature_this_sym, plugin.feature_this(f, n))
      end
    end

    define_singleton_method(n, -> { @plugins[n] }) unless respond_to?(n)
    @plugins[n] = plugin.new(self)
  end
  0
end