Module: Setsuzoku::Plugin
- Extended by:
- Forwardable, T::Helpers, T::Sig
- Defined in:
- lib/setsuzoku/plugin.rb
Overview
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.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- AVAILABLE_SERVICES =
{ web_service: Setsuzoku::Service::WebService::Service }
Instance Attribute Summary collapse
-
#config_context ⇒ Object
Returns the value of attribute config_context.
-
#name ⇒ Object
Returns the value of attribute name.
-
#registered_instance ⇒ Object
Returns the value of attribute registered_instance.
-
#service ⇒ Object
(also: #plugin_service)
Returns the value of attribute service.
Class Method Summary collapse
Instance Method Summary collapse
-
#final ⇒ Any
Convenience method for performing instance_exec on the registered_instance.
- #get_from_registered_instance_method(method_name, *args) ⇒ Object
- #get_registered_instance_val(val, *args) ⇒ Object
- #initialize(**options) ⇒ Object
Instance Attribute Details
#config_context ⇒ Object
Returns the value of attribute config_context.
20 21 22 |
# File 'lib/setsuzoku/plugin.rb', line 20 def config_context @config_context end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/setsuzoku/plugin.rb', line 17 def name @name end |
#registered_instance ⇒ Object
Returns the value of attribute registered_instance.
18 19 20 |
# File 'lib/setsuzoku/plugin.rb', line 18 def registered_instance @registered_instance end |
#service ⇒ Object Also known as: plugin_service
Returns the value of attribute service.
19 20 21 |
# File 'lib/setsuzoku/plugin.rb', line 19 def service @service end |
Class Method Details
.included(klass) ⇒ Object
30 31 32 |
# File 'lib/setsuzoku/plugin.rb', line 30 def self.included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#final ⇒ Any
Convenience method for performing instance_exec on the registered_instance. This is used for calling procs that are defined in the application’s registration procs.
82 |
# File 'lib/setsuzoku/plugin.rb', line 82 sig(:final) { params(options: T.untyped).returns(T.untyped) } |
#get_from_registered_instance_method(method_name, *args) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# 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) ⇒ Object
124 125 126 |
# 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 |
#initialize(**options) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/setsuzoku/plugin.rb', line 83 def initialize(**) context = self.class.config_context || { name: 'Default plugin', service: {} } self.name = context[:name] service_config = context[:service].except(:type).merge({ plugin: self, credential: [:credential] }) self.registered_instance = [: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(.except(:registering_instance)) self end |