module Setsuzoku::Plugin

The base definition for a plugin. A plugin is a unification of an ApiStrategy and an AuthStrategy. It allows each Strategy to manage its various jobs of sending/receiving requests, and managing authentication/connections. However it acts as the director that allows these 2 to interact with one another.

Constants

AVAILABLE_SERVICES

Attributes

config_context[RW]
name[RW]
plugin_service[RW]
registered_instance[RW]
service[RW]

Public Class Methods

included(klass) click to toggle source
# File lib/setsuzoku/plugin.rb, line 30
def self.included(klass)
  klass.extend(ClassMethods)
end
new(**options) click to toggle source
# File lib/setsuzoku/plugin.rb, line 83
def initialize(**options)
  context = self.class.config_context || { name: 'Default plugin', service: {} }
  self.name = context[:name]
  service_config = context[:service].except(:type).merge({ plugin: self, credential: options[:credential] })
  self.registered_instance = options[:registering_instance]
  if context[:service] && context[:service][:type]
    service = AVAILABLE_SERVICES[context[:service][:type]]
    self.service = service.new(service_config)
  end
  self.config_context = context.merge(options.except(:registering_instance))
  self
end

Public Instance Methods

get_from_registered_instance_method(method_name, *args) click to toggle source
# File lib/setsuzoku/plugin.rb, line 104
def get_from_registered_instance_method(method_name, *args)
  if self.registered_instance
    #either get the value if its defined generically in the
    val = self.config_context[:required_instance_methods][method_name.to_sym]
    self.get_registered_instance_val(val, *args)
  else
    #TODO: this needs to return any data type somehow...the plugin might need to stub this, as it stubs tests as well...
    # this seems like a reasonable approach...
    "stubbed_#{method_name}"
  end
end
get_registered_instance_val(val, *args) click to toggle source
# File lib/setsuzoku/plugin.rb, line 124
def get_registered_instance_val(val, *args)
  val.is_a?(Proc) ? self.registered_instance.instance_exec(*args, &val) : val
end