Module: Setsuzoku::Pluggable

Extended by:
Forwardable, T::Helpers, T::Sig
Defined in:
lib/setsuzoku/pluggable.rb

Overview

The module to include into a class to give it plugin functionality.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pluginObject

Returns the value of attribute plugin.



12
13
14
# File 'lib/setsuzoku/pluggable.rb', line 12

def plugin
  @plugin
end

Class Method Details

.included(klass) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/setsuzoku/pluggable.rb', line 15

def self.included(klass)
  klass.extend(ClassMethods)
  klass.class_eval do
    if klass.respond_to?(:after_initialize)
      after_initialize :assign_plugin
    else
      # Initialize the pluggable instance and associate its plugin.
      #
      # @param _args [Array] array of args passed into new. #unused
      # @param _block [Proc] the block passed into new. #unused
      #
      # @return [Class] the instance of the class that is pluggable.
      def initialize(*_args, &_block)
        super
        self.assign_plugin
        self
      end
    end
  end
end

Instance Method Details

#assign_plugin(*_args, &block) ⇒ Object



79
80
81
# File 'lib/setsuzoku/pluggable.rb', line 79

def assign_plugin(*_args, &block)
  self.plugin = self.class.plugin_context[:plugin_class].new(registering_instance: self, **self.class.plugin_context.except(:plugin_class))
end

#plugin_classObject



87
# File 'lib/setsuzoku/pluggable.rb', line 87

def plugin_class; end