fedux_org-stdlib 0.6.51 → 0.6.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fedux_org_stdlib/plugins/no_plugin.rb +21 -0
- data/lib/fedux_org_stdlib/plugins/plugin.rb +51 -0
- data/lib/fedux_org_stdlib/plugins/plugin_manager.rb +72 -0
- data/lib/fedux_org_stdlib/plugins.rb +1 -0
- data/lib/fedux_org_stdlib/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c0f9fee4d5504a9e084195a2792dc01c2e287d7
|
4
|
+
data.tar.gz: 94c4d4c5a82b6c1f9ca26b5746903ec26c7f3f15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 078097aaa6fe2a3016d9b549c04d1d92913776ef3bcf938fa028645e57f202ffe57518d5c18b5552bf9c3e5df6d9b5b5a7cdcc6d78f1dd53da799a495f872f32
|
7
|
+
data.tar.gz: f7b24e704b53e9abeed3a0c97a7c9d59ac21489a6c162a387c475318a68b9521ec6f05b5686df1d9a794dca11609c610d230c8670a660e1d68260277ee3d3ee0
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module FeduxOrgStdlib
|
3
|
+
module Plugins
|
4
|
+
# Placeholder when no associated gem found, displays warning
|
5
|
+
class NoPlugin
|
6
|
+
private
|
7
|
+
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
public
|
11
|
+
|
12
|
+
def initialize(name)
|
13
|
+
@name = name
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(*args)
|
17
|
+
warn "Warning: The plugin '#{name}' was not found! (no gem found)"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module FeduxOrgStdlib
|
3
|
+
module Plugins
|
4
|
+
class Plugin
|
5
|
+
attr_accessor :name, :gem_name, :enabled, :spec, :active
|
6
|
+
|
7
|
+
def initialize(name, gem_name, spec, enabled)
|
8
|
+
@name, @gem_name, @enabled, @spec = name, gem_name, enabled, spec
|
9
|
+
end
|
10
|
+
|
11
|
+
# Disable a plugin. (prevents plugin from being loaded, cannot
|
12
|
+
# disable an already activated plugin)
|
13
|
+
def disable!
|
14
|
+
self.enabled = false
|
15
|
+
end
|
16
|
+
|
17
|
+
# Enable a plugin. (does not load it immediately but puts on
|
18
|
+
# 'white list' to be loaded)
|
19
|
+
def enable!
|
20
|
+
self.enabled = true
|
21
|
+
end
|
22
|
+
|
23
|
+
# Activate the plugin (require the gem - enables/loads the
|
24
|
+
# plugin immediately at point of call, even if plugin is
|
25
|
+
# disabled)
|
26
|
+
# Does not reload plugin if it's already active.
|
27
|
+
def activate!
|
28
|
+
begin
|
29
|
+
if !active?
|
30
|
+
begin
|
31
|
+
require gem_name
|
32
|
+
rescue LoadError
|
33
|
+
require gem_name.gsub(/-/, '/')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
rescue LoadError => e
|
37
|
+
warn "Found plugin #{gem_name}, but could not require '#{gem_name}' or '#{gem_name.gsub(/-/, '/')}'"
|
38
|
+
warn e
|
39
|
+
rescue => e
|
40
|
+
warn "require '#{gem_name}' # Failed, saying: #{e}"
|
41
|
+
end
|
42
|
+
|
43
|
+
self.active = true
|
44
|
+
self.enabled = true
|
45
|
+
end
|
46
|
+
|
47
|
+
alias active? active
|
48
|
+
alias enabled? enabled
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'fedux_org_stdlib/plugins/no_plugin'
|
3
|
+
require 'fedux_org_stdlib/plugins/plugin'
|
4
|
+
|
5
|
+
module FeduxOrgStdlib
|
6
|
+
module Plugins
|
7
|
+
# Plugin Manager
|
8
|
+
#
|
9
|
+
# Make sure you've got a class method `.plugin_prefix` on your main module
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# # main module
|
13
|
+
# module FeduxOrgStdlib
|
14
|
+
# @plugin_manager = PluginManager.new
|
15
|
+
# @plugin_prefix = Regexp.new("^#{self.name.downcase.underscore}-")
|
16
|
+
#
|
17
|
+
# class << self
|
18
|
+
# attr_reader :plugin_prefix, :plugin_manager
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
class PluginManager
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :plugins
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
def initialize(plugins: [])
|
29
|
+
@plugins = plugins
|
30
|
+
end
|
31
|
+
|
32
|
+
# Find all installed plugins and store them in an internal array.
|
33
|
+
def locate_plugins
|
34
|
+
Gem.refresh
|
35
|
+
|
36
|
+
(Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem|
|
37
|
+
next if gem.name !~ self.class.deconstantize.plugin_prefix
|
38
|
+
|
39
|
+
plugin_name = gem.name.split('-', 2).last
|
40
|
+
@plugins << Plugin.new(plugin_name, gem.name, gem, true) if !gem_located?(gem.name)
|
41
|
+
end
|
42
|
+
|
43
|
+
@plugins
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Hash] A hash with all plugin names (minus the '<prefix>-') as
|
47
|
+
# keys and Plugin objects as values.
|
48
|
+
def plugins
|
49
|
+
h = Hash.new { |_, key| NoPlugin.new(key) }
|
50
|
+
|
51
|
+
@plugins.each do |plugin|
|
52
|
+
h[plugin.name] = plugin
|
53
|
+
end
|
54
|
+
|
55
|
+
h
|
56
|
+
end
|
57
|
+
|
58
|
+
# Require all enabled plugins, disabled plugins are skipped.
|
59
|
+
def load_plugins
|
60
|
+
@plugins.each do |plugin|
|
61
|
+
plugin.activate! if plugin.enabled?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def gem_located?(gem_name)
|
68
|
+
@plugins.any? { |plugin| plugin.gem_name == gem_name }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'fedux_org_stdlib/plugins/plugin_manager'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fedux_org-stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.52
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Meyer
|
@@ -84,6 +84,10 @@ files:
|
|
84
84
|
- lib/fedux_org_stdlib/models/class_based_model.rb
|
85
85
|
- lib/fedux_org_stdlib/models/exceptions.rb
|
86
86
|
- lib/fedux_org_stdlib/models/filesystem_based_model.rb
|
87
|
+
- lib/fedux_org_stdlib/plugins.rb
|
88
|
+
- lib/fedux_org_stdlib/plugins/no_plugin.rb
|
89
|
+
- lib/fedux_org_stdlib/plugins/plugin.rb
|
90
|
+
- lib/fedux_org_stdlib/plugins/plugin_manager.rb
|
87
91
|
- lib/fedux_org_stdlib/process_environment.rb
|
88
92
|
- lib/fedux_org_stdlib/project.rb
|
89
93
|
- lib/fedux_org_stdlib/project/generators/taskjuggler.rb
|