fedux_org-stdlib 0.6.54 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab784af842eb076d1daf729f886e73eaacb42553
4
- data.tar.gz: 9aa883cd9e21d5250198d77ab77cfae52dac709e
3
+ metadata.gz: 69cda4df42677eaa4cc55556b84ba2bb21238d0f
4
+ data.tar.gz: aa93c1328703d74dccd527ccdd508644167fadb4
5
5
  SHA512:
6
- metadata.gz: 80579d9e5ad8076e62cd8868d29ab8abd3fcef84ba14f4da31188739130093140bf273959e8f931f7b552df1175461262cb6587da9793c510ea615764a21dc6f
7
- data.tar.gz: 6f1423f64e8c31b4252ab5d2eb96eac6064491955bbd938905496e07089ae194ee06e6c7e54cbac864cb53ad293ac05e3806336a55ca7fada2c03021f0122291
6
+ metadata.gz: 6a19568a9601e924894c89aa3a5deb0cc5912195eea2bad36e1d105ea84492549b21d48562a4e2d20ee7da1507ed2fa1620b1195c221408c3f00e6730654cc73
7
+ data.tar.gz: 2c3da24e7b3b1dea080fd3cb09da656bb6633a63b1f3346b2f70c42f721457240d768d9ae98c88d481af63cbfb97492aa7ea4440168282c063f35e0bb919331f
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
- --require rspec/legacy_formatters
2
1
  --format Fuubar
3
2
  --order rand
4
3
  --color
data/Gemfile CHANGED
@@ -40,4 +40,7 @@ group :development, :test do
40
40
  gem 'yard'
41
41
  gem 'travis-lint'
42
42
  gem 'facter'
43
+
44
+ gem 'fedux_org_stdlib-fixtures-plugin_manager-plugin-load', require: false, path: File.expand_path('../fixtures/plugin-load-app', __FILE__)
45
+ gem 'fedux_org_stdlib-fixtures-plugin_manager-plugin-no_load', require: false, path: File.expand_path('../fixtures/plugin-no_load-app', __FILE__)
43
46
  end
@@ -1,9 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fedux_org-stdlib (0.6.53)
4
+ fedux_org-stdlib (0.6.55)
5
5
  activesupport
6
6
 
7
+ PATH
8
+ remote: fixtures/plugin-load-app
9
+ specs:
10
+ fedux_org_stdlib-fixtures-plugin_manager-plugin-load (0.0.1)
11
+
12
+ PATH
13
+ remote: fixtures/plugin-no_load-app
14
+ specs:
15
+ fedux_org_stdlib-fixtures-plugin_manager-plugin-no_load (0.0.1)
16
+
7
17
  GEM
8
18
  remote: https://rubygems.org/
9
19
  specs:
@@ -34,13 +44,13 @@ GEM
34
44
  activesupport
35
45
  smart_colored
36
46
  xml-simple
37
- coveralls (0.7.0)
47
+ coveralls (0.7.1)
38
48
  multi_json (~> 1.3)
39
49
  rest-client
40
50
  simplecov (>= 0.7)
41
51
  term-ansicolor
42
52
  thor
43
- cucumber (1.3.15)
53
+ cucumber (1.3.16)
44
54
  builder (>= 2.1.2)
45
55
  diff-lcs (>= 1.1.3)
46
56
  gherkin (~> 2.12)
@@ -55,8 +65,8 @@ GEM
55
65
  ffi (1.9.3)
56
66
  filegen (0.4.3)
57
67
  activesupport
58
- fuubar (1.3.3)
59
- rspec (>= 2.14.0, < 3.1.0)
68
+ fuubar (2.0.0)
69
+ rspec (~> 3.0)
60
70
  ruby-progressbar (~> 1.4)
61
71
  gherkin (2.12.2)
62
72
  multi_json (~> 1.3)
@@ -74,12 +84,12 @@ GEM
74
84
  multi_json (1.10.1)
75
85
  multi_test (0.1.1)
76
86
  netrc (0.7.7)
77
- parser (2.2.0.pre.3)
87
+ parser (2.2.0.pre.4)
78
88
  ast (>= 1.1, < 3.0)
79
89
  slop (~> 3.4, >= 3.4.5)
80
- posix-spawn (0.3.8)
90
+ posix-spawn (0.3.9)
81
91
  powerpack (0.0.9)
82
- pry (0.10.0)
92
+ pry (0.10.1)
83
93
  coderay (~> 1.1.0)
84
94
  method_source (~> 0.8.1)
85
95
  slop (~> 3.4)
@@ -99,20 +109,19 @@ GEM
99
109
  rspec-core (~> 3.0.0)
100
110
  rspec-expectations (~> 3.0.0)
101
111
  rspec-mocks (~> 3.0.0)
102
- rspec-core (3.0.2)
112
+ rspec-core (3.0.4)
103
113
  rspec-support (~> 3.0.0)
104
- rspec-expectations (3.0.2)
114
+ rspec-expectations (3.0.4)
105
115
  diff-lcs (>= 1.2.0, < 2.0)
106
116
  rspec-support (~> 3.0.0)
107
117
  rspec-legacy_formatters (1.0.0)
108
118
  rspec-core (>= 3.0.0.beta2)
109
119
  rspec-support (>= 3.0.0.beta2)
110
- rspec-mocks (3.0.2)
120
+ rspec-mocks (3.0.4)
111
121
  rspec-support (~> 3.0.0)
112
- rspec-support (3.0.2)
113
- rubocop (0.24.1)
114
- json (>= 1.7.7, < 2)
115
- parser (>= 2.2.0.pre.3, < 3.0)
122
+ rspec-support (3.0.4)
123
+ rubocop (0.25.0)
124
+ parser (>= 2.2.0.pre.4, < 3.0)
116
125
  powerpack (~> 0.0.6)
117
126
  rainbow (>= 1.99.1, < 3.0)
118
127
  ruby-progressbar (~> 1.4)
@@ -122,7 +131,7 @@ GEM
122
131
  multi_json
123
132
  simplecov-html (~> 0.8.0)
124
133
  simplecov-html (0.8.0)
125
- slop (3.5.0)
134
+ slop (3.6.0)
126
135
  smart_colored (1.1.1)
127
136
  taskjuggler (3.5.0)
128
137
  mail (>= 2.4.3)
@@ -131,12 +140,12 @@ GEM
131
140
  tins (~> 1.0)
132
141
  thor (0.19.1)
133
142
  thread_safe (0.3.4)
134
- tins (1.3.0)
143
+ tins (1.3.1)
135
144
  tmrb (1.2.7)
136
145
  thor
137
146
  travis-lint (2.0.0)
138
147
  json
139
- tzinfo (1.2.1)
148
+ tzinfo (1.2.2)
140
149
  thread_safe (~> 0.1)
141
150
  versionomy (0.4.4)
142
151
  blockenspiel (>= 0.4.5)
@@ -157,6 +166,8 @@ DEPENDENCIES
157
166
  erubis
158
167
  facter
159
168
  fedux_org-stdlib!
169
+ fedux_org_stdlib-fixtures-plugin_manager-plugin-load!
170
+ fedux_org_stdlib-fixtures-plugin_manager-plugin-no_load!
160
171
  filegen
161
172
  fuubar
162
173
  github-markup
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fedux_org_stdlib-fixtures-plugin_manager-plugin-load"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["Blub"]
9
+ spec.email = ["email@example.com"]
10
+ spec.summary = %q{Summary}
11
+ spec.homepage = ""
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ end
@@ -0,0 +1,13 @@
1
+ module FeduxOrgStdlib
2
+ module Fixtures
3
+ module PluginManager
4
+ module Plugin
5
+ module Load
6
+ def self.test1
7
+ 'test1'
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fedux_org_stdlib-fixtures-plugin_manager-plugin-no_load"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["blub"]
9
+ spec.email = ["example@email.com"]
10
+ spec.summary = %q{Summary}
11
+ spec.homepage = ""
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ end
@@ -0,0 +1,13 @@
1
+ module FeduxOrgStdlib
2
+ module Fixtures
3
+ module PluginManager
4
+ module Plugin
5
+ module NoLoad
6
+ def self.test1
7
+ 'test1'
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require 'fedux_org_stdlib/gem_plugins/plugin_manager'
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+ module FeduxOrgStdlib
3
+ module GemPlugins
4
+ end
5
+ end
@@ -1,8 +1,9 @@
1
1
  # encoding: utf-8
2
2
  module FeduxOrgStdlib
3
- module Plugins
3
+ module GemPlugins
4
4
  # Placeholder when no associated gem found, displays warning
5
5
  class NoPlugin
6
+
6
7
  private
7
8
 
8
9
  attr_reader :name
@@ -13,6 +14,11 @@ module FeduxOrgStdlib
13
14
  @name = name
14
15
  end
15
16
 
17
+ # Is not an existing plugin
18
+ def blank?
19
+ true
20
+ end
21
+
16
22
  def method_missing(*args)
17
23
  warn "Warning: The plugin '#{name}' was not found! (no gem found)"
18
24
  end
@@ -1,22 +1,31 @@
1
1
  # encoding: utf-8
2
2
  module FeduxOrgStdlib
3
- module Plugins
3
+ module GemPlugins
4
4
  class Plugin
5
- attr_accessor :name, :gem_name, :enabled, :spec, :active
6
5
 
7
- def initialize(name, gem_name, spec, enabled)
8
- @name, @gem_name, @enabled, @spec = name, gem_name, enabled, spec
6
+ private
7
+
8
+ attr_accessor :enabled, :active, :gem_name
9
+
10
+ public
11
+
12
+ attr_reader :name
13
+
14
+ def initialize(name, gem_name:, enabled:)
15
+ @name = name
16
+ @gem_name = gem_name
17
+ @enabled = enabled
9
18
  end
10
19
 
11
20
  # Disable a plugin. (prevents plugin from being loaded, cannot
12
21
  # disable an already activated plugin)
13
- def disable!
22
+ def disable
14
23
  self.enabled = false
15
24
  end
16
25
 
17
26
  # Enable a plugin. (does not load it immediately but puts on
18
27
  # 'white list' to be loaded)
19
- def enable!
28
+ def enable
20
29
  self.enabled = true
21
30
  end
22
31
 
@@ -24,7 +33,7 @@ module FeduxOrgStdlib
24
33
  # plugin immediately at point of call, even if plugin is
25
34
  # disabled)
26
35
  # Does not reload plugin if it's already active.
27
- def activate!
36
+ def activate
28
37
  begin
29
38
  if !active?
30
39
  begin
@@ -36,16 +45,28 @@ module FeduxOrgStdlib
36
45
  rescue LoadError => e
37
46
  warn "Found plugin #{gem_name}, but could not require '#{gem_name}' or '#{gem_name.gsub(/-/, '/')}'"
38
47
  warn e
39
- rescue => e
48
+ rescue StandardError => e
40
49
  warn "require '#{gem_name}' # Failed, saying: #{e}"
41
50
  end
42
51
 
43
- self.active = true
52
+ self.active = true
44
53
  self.enabled = true
45
54
  end
46
55
 
47
- alias active? active
48
- alias enabled? enabled
56
+ # Is plugin active?
57
+ def active?
58
+ active == true
59
+ end
60
+
61
+ # Is plugin enabled?
62
+ def enabled?
63
+ enabled == true
64
+ end
65
+
66
+ # Is an existing plugin
67
+ def blank?
68
+ false
69
+ end
49
70
  end
50
71
  end
51
72
  end
@@ -0,0 +1,140 @@
1
+ # encoding: utf-8
2
+ require 'fedux_org_stdlib/gem_plugins/no_plugin'
3
+ require 'fedux_org_stdlib/gem_plugins/plugin'
4
+ require 'fedux_org_stdlib/gem_plugins/exceptions'
5
+
6
+ require_library %w( active_support/core_ext/string/inflections active_support/core_ext/object/blank )
7
+
8
+ module FeduxOrgStdlib
9
+ module GemPlugins
10
+ # Plugin Manager
11
+ #
12
+ # To use the plugin manager you should build the plugins for your
13
+ # application as rubygems. How you name the plugins is up to you, but it is
14
+ # recommended to use something like `your-application-<plugin>`, where
15
+ # `your-application-` is the prefix (please mind the dash at the end).
16
+ #
17
+ # @example Default prefix
18
+ #
19
+ # # -- main.rb --
20
+ # # main module
21
+ # module YourApplication
22
+ # # The manager uses "#{self.name.underscore.gsub(/\//, '-')}-" as prefix
23
+ # @plugin_manager = PluginManager.new
24
+ #
25
+ # class << self
26
+ # attr_reader :plugin_manager
27
+ #
28
+ # def load_plugins
29
+ # self.plugin_manager.load_plugins
30
+ # end
31
+ # end
32
+ # end
33
+ #
34
+ #
35
+ # @example Use different prefix
36
+ # # -- main.rb --
37
+ # # main module
38
+ # module YourApplication
39
+ # # The manager uses 'asdf-' as prefix
40
+ # @plugin_manager = PluginManager.new(prefix: 'asdf-')
41
+ #
42
+ # [...]
43
+ # end
44
+ #
45
+ # At some place you need to load your plugins.
46
+ #
47
+ # @example Load plugins in your application
48
+ #
49
+ # # -- runner.rb --
50
+ #
51
+ # YourApplication.load_plugins
52
+ #
53
+ class PluginManager
54
+
55
+ private
56
+
57
+ attr_reader :plugins, :prefix, :whitelist, :blacklist
58
+
59
+ public
60
+
61
+ def initialize(prefix: __plugin_prefix, whitelist: [], blacklist: [])
62
+ @prefix = Regexp.new(prefix)
63
+ @whitelist = Array(whitelist)
64
+ @blacklist = Array(blacklist)
65
+
66
+ # needs variables above
67
+ @plugins = locate_plugins
68
+ end
69
+
70
+ # Disable a plugin
71
+ def disable_plugin(name)
72
+ plugin = plugins.find(NoPlugin.new(name)) { |p| p.name == name }
73
+
74
+ return if plugin.blank?
75
+
76
+ plugin.disable
77
+ end
78
+
79
+ # Enable a plugin
80
+ def enable_plugin(name)
81
+ plugin = plugins.find(NoPlugin.new(name)) { |p| p.name == name }
82
+
83
+ return if plugin.blank?
84
+
85
+ plugin.enable
86
+ end
87
+
88
+ # Require all enabled plugins, disabled plugins are skipped.
89
+ def load_plugins
90
+ each_enabled_plugin { |p| p.activate }
91
+ end
92
+
93
+ private
94
+
95
+ def each_enabled_plugin(&block)
96
+ plugins.find_all { |p| p.enabled? }.each(&block)
97
+ end
98
+
99
+ # Find all installed plugins and store them in an internal array.
100
+ def locate_plugins
101
+ plgs = []
102
+
103
+ Gem.refresh
104
+
105
+ (Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem|
106
+ name = gem.name.sub(prefix, '')
107
+
108
+ next if gem.name !~ prefix
109
+ next if plgs.any? { |plugin| plugin.name == name }
110
+
111
+ enabled = if !whitelist.blank? && !whitelist.include?(name)
112
+ false
113
+ elsif !blacklist.blank? && blacklist.include?(name)
114
+ false
115
+ else
116
+ true
117
+ end
118
+
119
+ plgs << Plugin.new(
120
+ name,
121
+ gem_name: gem.name,
122
+ enabled: enabled,
123
+ )
124
+ end
125
+
126
+ plgs
127
+ end
128
+
129
+ def __plugin_prefix
130
+ name = if self.class.name.deconstantize.blank?
131
+ self.class.name
132
+ else
133
+ self.class.name.deconstantize
134
+ end
135
+
136
+ "#{name.underscore.gsub(/\//, '-')}-"
137
+ end
138
+ end
139
+ end
140
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # FeduxOrgStdlib
3
3
  module FeduxOrgStdlib
4
- VERSION = '0.6.54'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require 'active_support/core_ext/string/inflections'
3
+
4
+ RSpec::Matchers.define :be_defined do
5
+ match do |actual|
6
+ begin
7
+ actual.constantize
8
+
9
+ return true
10
+ rescue StandardError
11
+ return false
12
+ end
13
+ end
14
+
15
+ failure_message do |actual|
16
+ "expected that #{actual} should be defined"
17
+ end
18
+
19
+ failure_message_when_negated do |actual|
20
+ "expected that #{actual} should not be defined"
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'fedux_org_stdlib/gem_plugins/plugin_manager'
4
+
5
+ RSpec.describe GemPlugins::PluginManager do
6
+ context '#load_plugins' do
7
+ it 'loads available plugins' do
8
+ manager = GemPlugins::PluginManager.new prefix: 'fedux_org_stdlib-fixtures-plugin_manager-'
9
+ manager.disable_plugin 'plugin-no_load'
10
+ manager.load_plugins
11
+
12
+ expect('FeduxOrgStdlib::Fixtures::PluginManager::Plugin::Load').to be_defined
13
+ end
14
+ end
15
+
16
+ context '#disable' do
17
+ it 'disable plugin' do
18
+ manager = GemPlugins::PluginManager.new prefix: 'fedux_org_stdlib-fixtures-plugin_manager-'
19
+ manager.disable_plugin 'plugin-no_load'
20
+ manager.load_plugins
21
+
22
+ expect('FeduxOrgStdlib::Fixtures::PluginManager::Plugin::NoLoad').not_to be_defined
23
+ end
24
+
25
+ it 'outputs warning if plugin cannout be found' do
26
+ manager = GemPlugins::PluginManager.new prefix: 'fedux_org_stdlib-fixtures-plugin_manager-'
27
+ result = capture :stderr do
28
+ manager.disable_plugin 'plugin-blub'
29
+ end
30
+
31
+ expect(result).to include 'plugin-blub'
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,4 @@
1
1
  # encoding: utf-8
2
- #
3
2
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
4
3
  require 'fedux_org_stdlib'
5
4
  # Avoid writing "describe MyModule::MyClass do [..]" but "describe MyClass do [..]"
@@ -15,6 +14,7 @@ Bundler.require :default, :test, :development
15
14
 
16
15
  # Loading support files
17
16
  Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
17
+ Dir.glob(::File.expand_path('../matchers/*.rb', __FILE__)).each { |f| require_relative f }
18
18
 
19
19
 
20
20
  def examples_dir
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.54
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-14 00:00:00.000000000 Z
11
+ date: 2014-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -47,6 +47,10 @@ files:
47
47
  - doc/logic_converters.md
48
48
  - doc/models.md
49
49
  - fedux_org-stdlib.gemspec
50
+ - fixtures/plugin-load-app/fedux_org_stdlib-fixtures-plugin_manager-plugin-load.gemspec
51
+ - fixtures/plugin-load-app/lib/fedux_org_stdlib/fixtures/plugin_manager/plugin/load.rb
52
+ - fixtures/plugin-no_load-app/fedux_org_stdlib-fixtures-plugin_manager-plugin-no_load.gemspec
53
+ - fixtures/plugin-no_load-app/lib/fedux_org_stdlib/fixtures/plugin_manager/plugin/no_load.rb
50
54
  - lib/fedux_org_stdlib.rb
51
55
  - lib/fedux_org_stdlib/app_config.rb
52
56
  - lib/fedux_org_stdlib/app_config/exceptions.rb
@@ -69,6 +73,11 @@ files:
69
73
  - lib/fedux_org_stdlib/file_template/exceptions.rb
70
74
  - lib/fedux_org_stdlib/filesystem.rb
71
75
  - lib/fedux_org_stdlib/filesystem/exceptions.rb
76
+ - lib/fedux_org_stdlib/gem_plugins.rb
77
+ - lib/fedux_org_stdlib/gem_plugins/exceptions.rb
78
+ - lib/fedux_org_stdlib/gem_plugins/no_plugin.rb
79
+ - lib/fedux_org_stdlib/gem_plugins/plugin.rb
80
+ - lib/fedux_org_stdlib/gem_plugins/plugin_manager.rb
72
81
  - lib/fedux_org_stdlib/logging.rb
73
82
  - lib/fedux_org_stdlib/logging/logger.rb
74
83
  - lib/fedux_org_stdlib/logging/severity.rb
@@ -85,9 +94,6 @@ files:
85
94
  - lib/fedux_org_stdlib/models/exceptions.rb
86
95
  - lib/fedux_org_stdlib/models/filesystem_based_model.rb
87
96
  - 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
91
97
  - lib/fedux_org_stdlib/process_environment.rb
92
98
  - lib/fedux_org_stdlib/project.rb
93
99
  - lib/fedux_org_stdlib/project/generators/taskjuggler.rb
@@ -172,9 +178,11 @@ files:
172
178
  - spec/logic_converters/true_false_converter_spec.rb
173
179
  - spec/logic_converters/y_n_converter_spec.rb
174
180
  - spec/logic_converters/yes_no_converter_spec.rb
181
+ - spec/matchers/is_defined.rb
175
182
  - spec/models/base_model_spec.rb
176
183
  - spec/models/class_based_model_spec.rb
177
184
  - spec/models/filesystem_based_model_spec.rb
185
+ - spec/plugins/plugin_manager_spec.rb
178
186
  - spec/project/plan_spec.rb
179
187
  - spec/project/report_spec.rb
180
188
  - spec/project/taskjuggler_spec.rb
@@ -246,9 +254,11 @@ test_files:
246
254
  - spec/logic_converters/true_false_converter_spec.rb
247
255
  - spec/logic_converters/y_n_converter_spec.rb
248
256
  - spec/logic_converters/yes_no_converter_spec.rb
257
+ - spec/matchers/is_defined.rb
249
258
  - spec/models/base_model_spec.rb
250
259
  - spec/models/class_based_model_spec.rb
251
260
  - spec/models/filesystem_based_model_spec.rb
261
+ - spec/plugins/plugin_manager_spec.rb
252
262
  - spec/project/plan_spec.rb
253
263
  - spec/project/report_spec.rb
254
264
  - spec/project/taskjuggler_spec.rb
@@ -1,102 +0,0 @@
1
- # encoding: utf-8
2
- require 'fedux_org_stdlib/plugins/no_plugin'
3
- require 'fedux_org_stdlib/plugins/plugin'
4
-
5
- require_library %w{ json active_support/core_ext/string/inflections }
6
-
7
- module FeduxOrgStdlib
8
- module Plugins
9
- # Plugin Manager
10
- #
11
- # Make sure you've got a class method `.plugin_prefix` on your main module
12
- #
13
- # @example
14
- # # -- main.rb --
15
- # # main module
16
- # module YourApplication
17
- # # The manager
18
- # @plugin_manager = PluginManager.new
19
- #
20
- # # This regex depends on your application's plugins file system structure
21
- # @plugin_prefix = Regexp.new("^#{self.name.underscore.gsub(/\//, '-')}-")
22
- #
23
- # class << self
24
- # attr_reader :plugin_prefix, :plugin_manager
25
- #
26
- # def load_plugins
27
- # self.plugin_manager.locate_plugins
28
- # self.plugin_manager.load_plugins
29
- # end
30
- # end
31
- # end
32
- #
33
- # At some place you need to load your plugins.
34
- #
35
- # @example
36
- #
37
- # # -- runner.rb --
38
- #
39
- # YourApplication.load_plugins
40
- #
41
- class PluginManager
42
- private
43
-
44
- attr_reader :plugins
45
-
46
- public
47
-
48
- def initialize(plugins: [])
49
- @plugins = plugins
50
- end
51
-
52
- # Find all installed plugins and store them in an internal array.
53
- def locate_plugins
54
- Gem.refresh
55
-
56
- (Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem|
57
- next if gem.name !~ plugin_prefix
58
-
59
- plugin_name = gem.name.split('-', 2).last
60
- @plugins << Plugin.new(plugin_name, gem.name, gem, true) if !gem_located?(gem.name)
61
- end
62
-
63
- @plugins
64
- end
65
-
66
- # @return [Hash] A hash with all plugin names (minus the '<prefix>-') as
67
- # keys and Plugin objects as values.
68
- def plugins
69
- h = Hash.new { |_, key| NoPlugin.new(key) }
70
-
71
- @plugins.each do |plugin|
72
- h[plugin.name] = plugin
73
- end
74
-
75
- h
76
- end
77
-
78
- # Require all enabled plugins, disabled plugins are skipped.
79
- def load_plugins
80
- @plugins.each do |plugin|
81
- plugin.activate! if plugin.enabled?
82
- end
83
- end
84
-
85
- private
86
-
87
- def gem_located?(gem_name)
88
- @plugins.any? { |plugin| plugin.gem_name == gem_name }
89
- end
90
-
91
- def plugin_prefix
92
- module_name = if self.class.name.deconstantize.blank?
93
- self.class.name
94
- else
95
- self.class.name.deconstantize
96
- end
97
-
98
- module_name.constantize.plugin_prefix
99
- end
100
- end
101
- end
102
- end