Module: Ecko::Plugins

Defined in:
lib/ecko/plugins.rb,
lib/ecko/plugins/version.rb

Defined Under Namespace

Classes: Error, PluginPresentError, Registry

Constant Summary collapse

VERSION =
'0.1.6'
@@registry =

Set a registry variable to help cache all the registries

{}

Class Method Summary collapse

Class Method Details

.execute_pipeline(registered_plugin, schema) ⇒ Object

Pipeline just includes configuration currently, It will help us run a validation pipeline in the future. TODO: Update the comment on the method when upgraded.



37
38
39
# File 'lib/ecko/plugins.rb', line 37

def execute_pipeline(registered_plugin, schema)
  registered_plugin.configure(schema)
end

.register(name:, schema:, engine:) ⇒ Object

Registers a new plugin, A plugin with the same name cannot be registered twice That will raise Ecko::Plugins::PluginPresentError if a plugin is already registered. name: Name of the plugin in snail case schema: hash/object or any data structure which defines the plugin engine: It is a class which exposes a configure class definition(method)



24
25
26
27
28
29
30
31
32
33
# File 'lib/ecko/plugins.rb', line 24

def register(name:, schema:, engine:)
  raise Ecko::Plugins::PluginPresentError unless Ecko::Plugins.registry[name].nil?

  # This helps set a new reference class which will be used as a pristine class. It doesnt have a big
  # role currently but will serve a great deal of purpose in the future.
  registered_plugin = Ecko::Plugins::Registry.const_set(name.capitalize, Class.new(engine))
  Ecko::Plugins.registry[name] = { schema: schema, engine: engine, engine_stub: registered_plugin }
  register_method(name, registered_plugin)
  execute_pipeline(registered_plugin, schema)
end

.register_method(name, engine) ⇒ Object

Creates a singleton class to help devs use the plugin engine and run methods accordingly.



42
43
44
45
46
# File 'lib/ecko/plugins.rb', line 42

def register_method(name, engine)
  define_singleton_method name do
    engine
  end
end

.registryObject



15
16
17
# File 'lib/ecko/plugins.rb', line 15

def registry
  @@registry
end