Class: Fusuma::Plugin::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/plugin/base.rb

Overview

Create a Plugin Class with extending this class

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inherited(subclass) ⇒ Object

when inherited from subclass



12
13
14
15
16
# File 'lib/fusuma/plugin/base.rb', line 12

def self.inherited(subclass)
  super
  subclass_path = caller_locations(1..1).first.path
  Manager.add(plugin_class: subclass, plugin_path: subclass_path)
end

.pluginsArray<Class>

get subclasses

Returns:

  • (Array<Class>)


20
21
22
# File 'lib/fusuma/plugin/base.rb', line 20

def self.plugins
  Manager.plugins[name]
end

Instance Method Details

#config_indexObject



62
63
64
# File 'lib/fusuma/plugin/base.rb', line 62

def config_index
  @config_index ||= Config::Index.new(self.class.name.gsub("Fusuma::", "").underscore.split("/"))
end

#config_param_typesHash

config parameter name and Type of the value of parameter

Returns:

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/fusuma/plugin/base.rb', line 30

def config_param_types
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end

#config_params(key = nil) ⇒ Object

Parameters:

Returns:

  • (Object)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fusuma/plugin/base.rb', line 37

def config_params(key = nil)
  @config_params ||= {}
  if @config_params["#{config_index.cache_key},#{key}"]
    return @config_params["#{config_index.cache_key},#{key}"]
  end

  params = Config.instance.fetch_config_params(key, config_index)

  return params unless key

  @config_params["#{config_index.cache_key},#{key}"] =
    params.fetch(key, nil).tap do |val|
      next if val.nil?

      # NOTE: Type checking for config.yml
      param_types = Array(config_param_types.fetch(key))

      next if param_types.any? { |klass| val.is_a?(klass) }

      MultiLogger.error("Please fix config.yml")
      MultiLogger.error("`#{config_index.keys.join(".")}.#{key}` should be #{param_types.join(" OR ")}.")
      exit 1
    end
end

#shutdownObject

This method is abstract.

override ‘#shutdown` to implement



25
26
# File 'lib/fusuma/plugin/base.rb', line 25

def shutdown
end