Module: Fabriq::PluginPort

Extended by:
Logging, PluginPort
Included in:
PluginPort
Defined in:
lib/fabriq/plugin_port.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

config, debug, error, info, send_output

Instance Attribute Details

#pluginsObject

Returns the value of attribute plugins.



6
7
8
# File 'lib/fabriq/plugin_port.rb', line 6

def plugins
  @plugins
end

Instance Method Details

#initialize_pluginsObject



46
47
48
49
50
# File 'lib/fabriq/plugin_port.rb', line 46

def initialize_plugins
  @plugins.each do |plugin|
    invoke_plugin_callback(plugin, :initialized)
  end
end

#plugin_load_pathsObject



8
9
10
11
12
# File 'lib/fabriq/plugin_port.rb', line 8

def plugin_load_paths
  [File.expand_path("~") + "/.fabriq", Dir.pwd].collect do |base_path|
    Dir.glob("#{base_path}/plugins/*")
  end.flatten
end

#register_plugin(klass, &config_block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fabriq/plugin_port.rb', line 33

def register_plugin(klass, &config_block)
  @plugins ||= []

  plugin = klass.init

  if block_given? && plugin.respond_to?(:configurator)
    config_block.call(plugin.configurator)
  end

  invoke_plugin_callback(plugin, :registered)
  @plugins << plugin
end

#require_plugin_from_path(plugin_base_dir) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/fabriq/plugin_port.rb', line 23

def require_plugin_from_path(plugin_base_dir)
  plugin_name = plugin_base_dir.split("/").last
  base_file_path = File.join(plugin_base_dir, "lib", "#{plugin_name}.rb")
  if File.exist?(base_file_path)
    require base_file_path
  else
    error("Plugin: #{plugin_name} - Base file not found (#{base_file_path}")
  end
end

#require_pluginsObject



14
15
16
17
18
19
20
21
# File 'lib/fabriq/plugin_port.rb', line 14

def require_plugins
  debug "Plugin Load paths: #{plugin_load_paths}"

  plugin_load_paths.each do |plugin_base_dir|
    next unless File.exist?(plugin_base_dir)
    require_plugin_from_path plugin_base_dir
  end
end