Module: YleTf::Plugin::Loader

Defined in:
lib/yle_tf/plugin/loader.rb

Constant Summary collapse

BUNDLER_PLUGIN_GROUP =
:tf_plugins

Class Method Summary collapse

Class Method Details

.bundler_pluginsObject



39
40
41
42
43
44
# File 'lib/yle_tf/plugin/loader.rb', line 39

def self.bundler_plugins
  plugins = Bundler.definition.current_dependencies.select do |dep|
    dep.groups.include?(BUNDLER_PLUGIN_GROUP)
  end
  plugins.map { |dep| Bundler.definition.specs[dep].first }
end

.bundler_set_up?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/yle_tf/plugin/loader.rb', line 50

def self.bundler_set_up?
  defined?(Bundler) && Bundler.respond_to?(:require)
end

.core_pluginsObject



35
36
37
# File 'lib/yle_tf/plugin/loader.rb', line 35

def self.core_plugins
  Dir.glob(File.expand_path('../../../yle_tf_plugins/**/plugin.rb', __FILE__))
end

.load_bundler_pluginsObject



21
22
23
24
25
26
# File 'lib/yle_tf/plugin/loader.rb', line 21

def self.load_bundler_plugins
  return if !bundler_set_up?

  print_bundler_plugin_list if Logger.debug?
  Bundler.require(BUNDLER_PLUGIN_GROUP)
end

.load_core_pluginsObject



14
15
16
17
18
19
# File 'lib/yle_tf/plugin/loader.rb', line 14

def self.load_core_plugins
  core_plugins.each do |plugin_file|
    Logger.debug("Loading core plugin: #{File.basename(plugin_file, '.rb')}")
    load(plugin_file)
  end
end

.load_pluginsObject



8
9
10
11
12
# File 'lib/yle_tf/plugin/loader.rb', line 8

def self.load_plugins
  load_core_plugins
  load_bundler_plugins
  load_user_plugins
end

.load_user_pluginsObject



28
29
30
31
32
33
# File 'lib/yle_tf/plugin/loader.rb', line 28

def self.load_user_plugins
  user_plugins.each do |plugin|
    Logger.debug("Loading user plugin: #{plugin}")
    require(plugin)
  end
end


54
55
56
57
58
59
60
# File 'lib/yle_tf/plugin/loader.rb', line 54

def self.print_bundler_plugin_list
  plugins = bundler_plugins
  if !plugins.empty?
    Logger.debug('Loading plugins via Bundler:')
    plugins.each { |spec| Logger.debug("  - #{spec.name} = #{spec.version}") }
  end
end

.user_pluginsObject



46
47
48
# File 'lib/yle_tf/plugin/loader.rb', line 46

def self.user_plugins
  ENV.fetch('TF_PLUGINS', '').split(/[ ,]+/)
end