Class: Fusuma::Plugin::Base

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

Overview

Create a Plugin Class with extending this class

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CustomProcess

#fork

Class Method Details

.inherited(subclass) ⇒ Object

when inherited from subclass



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

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>)


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

def self.plugins
  Manager.plugins[name]
end

Instance Method Details

#config_indexObject



54
55
56
# File 'lib/fusuma/plugin/base.rb', line 54

def 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)


27
28
29
# File 'lib/fusuma/plugin/base.rb', line 27

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

#config_params(key = nil, base: config_index) ⇒ Object

Returns:

  • (Object)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fusuma/plugin/base.rb', line 32

def config_params(key = nil, base: config_index)
  params = Config.search(base) || {}

  return params unless key

  @config_params ||= {}
  @config_params["#{base.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(":#{base.keys.map(&:symbol)
      .join(' => :')} => :#{key} should be #{param_types.join(' OR ')}.")
      exit 1
    end
end