class Dry::System::Plugins::Plugin

@api private

Attributes

block[R]
mod[R]
name[R]

Public Class Methods

new(name, mod, &block) click to toggle source

@api private

# File lib/dry/system/plugins.rb, line 17
def initialize(name, mod, &block)
  @name = name
  @mod = mod
  @block = block
end

Public Instance Methods

apply_to(system, options) click to toggle source

@api private

# File lib/dry/system/plugins.rb, line 24
def apply_to(system, options)
  system.extend(stateful? ? mod.new(options) : mod)
  system.instance_eval(&block) if block
  system
end
load_dependencies(dependencies = mod_dependencies, gem = nil) click to toggle source

@api private

# File lib/dry/system/plugins.rb, line 31
def load_dependencies(dependencies = mod_dependencies, gem = nil)
  Array(dependencies).each do |dependency|
    if dependency.is_a?(Array) || dependency.is_a?(Hash)
      dependency.each { |value| load_dependencies(*Array(value).reverse) }
    elsif !Plugins.loaded_dependencies.include?(dependency.to_s)
      load_dependency(dependency, gem)
    end
  end
end
load_dependency(dependency, gem) click to toggle source

@api private

# File lib/dry/system/plugins.rb, line 42
def load_dependency(dependency, gem)
  Kernel.require dependency
  Plugins.loaded_dependencies << dependency.to_s
rescue LoadError => e
  raise PluginDependencyMissing.new(name, e.message, gem)
end
mod_dependencies() click to toggle source

@api private

# File lib/dry/system/plugins.rb, line 55
def mod_dependencies
  return EMPTY_ARRAY unless mod.respond_to?(:dependencies)

  mod.dependencies.is_a?(Array) ? mod.dependencies : [mod.dependencies]
end
stateful?() click to toggle source

@api private

# File lib/dry/system/plugins.rb, line 50
def stateful?
  mod < Module
end