nucleon 0.1.19 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +1 -0
- data/TODO.rdoc +0 -3
- data/VERSION +1 -1
- data/bin/nucleon +19 -0
- data/lib/core/config.rb +11 -7
- data/lib/core/environment.rb +338 -0
- data/lib/core/facade.rb +150 -98
- data/lib/core/manager.rb +160 -249
- data/lib/core/mixin/action/project.rb +2 -2
- data/lib/core/mixin/macro/plugin_interface.rb +11 -11
- data/lib/core/plugin/action.rb +277 -24
- data/lib/core/plugin/base.rb +22 -14
- data/lib/core/plugin/command.rb +1 -1
- data/lib/core/plugin/event.rb +3 -3
- data/lib/core/plugin/extension.rb +1 -1
- data/lib/core/plugin/project.rb +15 -15
- data/lib/core/plugin/template.rb +1 -1
- data/lib/core/plugin/translator.rb +1 -1
- data/lib/core/util/cache.rb +1 -1
- data/lib/core/util/cli.rb +32 -3
- data/lib/core/util/console.rb +30 -10
- data/lib/core/util/data.rb +11 -3
- data/lib/core/util/logger.rb +1 -1
- data/lib/core/util/shell.rb +6 -3
- data/lib/core/util/ssh.rb +148 -24
- data/lib/nucleon/action/extract.rb +11 -4
- data/lib/nucleon/action/{add.rb → project/add.rb} +13 -4
- data/lib/nucleon/action/{create.rb → project/create.rb} +12 -3
- data/lib/nucleon/action/{remove.rb → project/remove.rb} +11 -2
- data/lib/nucleon/action/{save.rb → project/save.rb} +11 -2
- data/lib/nucleon/action/{update.rb → project/update.rb} +11 -2
- data/lib/nucleon/command/bash.rb +1 -1
- data/lib/nucleon/event/regex.rb +1 -1
- data/lib/nucleon/project/git.rb +3 -3
- data/lib/nucleon/template/{json.rb → JSON.rb} +1 -1
- data/lib/nucleon/template/{yaml.rb → YAML.rb} +1 -1
- data/lib/nucleon/template/wrapper.rb +1 -1
- data/lib/nucleon/translator/{json.rb → JSON.rb} +1 -1
- data/lib/nucleon/translator/{yaml.rb → YAML.rb} +1 -1
- data/lib/nucleon_base.rb +26 -15
- data/locales/en.yml +69 -44
- data/nucleon.gemspec +129 -11
- data/rdoc/site/0.1.19/ARCHITECTURE_rdoc.html +634 -0
- data/rdoc/site/0.1.19/Hash.html +347 -0
- data/rdoc/site/0.1.19/Kernel.html +413 -0
- data/rdoc/site/0.1.19/Nucleon.html +570 -0
- data/rdoc/site/0.1.19/Nucleon/Action.html +280 -0
- data/rdoc/site/0.1.19/Nucleon/Action/Add.html +458 -0
- data/rdoc/site/0.1.19/Nucleon/Action/Create.html +415 -0
- data/rdoc/site/0.1.19/Nucleon/Action/Extract.html +413 -0
- data/rdoc/site/0.1.19/Nucleon/Action/Remove.html +461 -0
- data/rdoc/site/0.1.19/Nucleon/Action/Save.html +434 -0
- data/rdoc/site/0.1.19/Nucleon/Action/Update.html +381 -0
- data/rdoc/site/0.1.19/Nucleon/Codes.html +563 -0
- data/rdoc/site/0.1.19/Nucleon/Command.html +275 -0
- data/rdoc/site/0.1.19/Nucleon/Command/Bash.html +544 -0
- data/rdoc/site/0.1.19/Nucleon/Config.html +1623 -0
- data/rdoc/site/0.1.19/Nucleon/Config/Collection.html +509 -0
- data/rdoc/site/0.1.19/Nucleon/Config/Options.html +489 -0
- data/rdoc/site/0.1.19/Nucleon/Core.html +635 -0
- data/rdoc/site/0.1.19/Nucleon/Errors.html +275 -0
- data/rdoc/site/0.1.19/Nucleon/Errors/BatchError.html +281 -0
- data/rdoc/site/0.1.19/Nucleon/Errors/NucleonError.html +657 -0
- data/rdoc/site/0.1.19/Nucleon/Errors/SSHUnavailable.html +281 -0
- data/rdoc/site/0.1.19/Nucleon/Event.html +275 -0
- data/rdoc/site/0.1.19/Nucleon/Event/Regex.html +467 -0
- data/rdoc/site/0.1.19/Nucleon/Facade.html +2336 -0
- data/rdoc/site/0.1.19/Nucleon/Gems.html +635 -0
- data/rdoc/site/0.1.19/Nucleon/Manager.html +1828 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin.html +284 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/Action.html +277 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/Action/Commit.html +381 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/Action/Project.html +395 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/Action/Push.html +371 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/Colors.html +545 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/ConfigCollection.html +481 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/ConfigOptions.html +449 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/Macro.html +276 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/Macro/ObjectInterface.html +695 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/Macro/PluginInterface.html +682 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/Settings.html +481 -0
- data/rdoc/site/0.1.19/Nucleon/Mixin/SubConfig.html +887 -0
- data/rdoc/site/0.1.19/Nucleon/Parallel.html +325 -0
- data/rdoc/site/0.1.19/Nucleon/Parallel/ClassMethods.html +325 -0
- data/rdoc/site/0.1.19/Nucleon/Parallel/InstanceMethods.html +334 -0
- data/rdoc/site/0.1.19/Nucleon/Plugin.html +282 -0
- data/rdoc/site/0.1.19/Nucleon/Plugin/Action.html +1368 -0
- data/rdoc/site/0.1.19/Nucleon/Plugin/Action/Option.html +459 -0
- data/rdoc/site/0.1.19/Nucleon/Plugin/Base.html +1737 -0
- data/rdoc/site/0.1.19/Nucleon/Plugin/Command.html +721 -0
- data/rdoc/site/0.1.19/Nucleon/Plugin/Event.html +442 -0
- data/rdoc/site/0.1.19/Nucleon/Plugin/Extension.html +281 -0
- data/rdoc/site/0.1.19/Nucleon/Plugin/Project.html +2864 -0
- data/rdoc/site/0.1.19/Nucleon/Plugin/Template.html +476 -0
- data/rdoc/site/0.1.19/Nucleon/Plugin/Translator.html +371 -0
- data/rdoc/site/0.1.19/Nucleon/Project.html +276 -0
- data/rdoc/site/0.1.19/Nucleon/Project/Git.html +1801 -0
- data/rdoc/site/0.1.19/Nucleon/Project/Github.html +549 -0
- data/rdoc/site/0.1.19/Nucleon/Template.html +277 -0
- data/rdoc/site/0.1.19/Nucleon/Template/Json.html +329 -0
- data/rdoc/site/0.1.19/Nucleon/Template/Wrapper.html +329 -0
- data/rdoc/site/0.1.19/Nucleon/Template/Yaml.html +329 -0
- data/rdoc/site/0.1.19/Nucleon/Translator.html +276 -0
- data/rdoc/site/0.1.19/Nucleon/Translator/Json.html +366 -0
- data/rdoc/site/0.1.19/Nucleon/Translator/Yaml.html +366 -0
- data/rdoc/site/0.1.19/Nucleon/Util.html +285 -0
- data/rdoc/site/0.1.19/Nucleon/Util/CLI.html +388 -0
- data/rdoc/site/0.1.19/Nucleon/Util/CLI/Parser.html +1183 -0
- data/rdoc/site/0.1.19/Nucleon/Util/Cache.html +780 -0
- data/rdoc/site/0.1.19/Nucleon/Util/Console.html +1294 -0
- data/rdoc/site/0.1.19/Nucleon/Util/Data.html +1399 -0
- data/rdoc/site/0.1.19/Nucleon/Util/Disk.html +522 -0
- data/rdoc/site/0.1.19/Nucleon/Util/Git.html +361 -0
- data/rdoc/site/0.1.19/Nucleon/Util/Liquid.html +365 -0
- data/rdoc/site/0.1.19/Nucleon/Util/Logger.html +806 -0
- data/rdoc/site/0.1.19/Nucleon/Util/Package.html +558 -0
- data/rdoc/site/0.1.19/Nucleon/Util/SSH.html +910 -0
- data/rdoc/site/0.1.19/Nucleon/Util/SSH/Keypair.html +453 -0
- data/rdoc/site/0.1.19/Nucleon/Util/Shell.html +686 -0
- data/rdoc/site/0.1.19/Nucleon/Util/Shell/Result.html +497 -0
- data/rdoc/site/0.1.19/README_rdoc.html +312 -0
- data/rdoc/site/0.1.19/TODO_rdoc.html +267 -0
- data/rdoc/site/0.1.19/created.rid +60 -0
- data/rdoc/site/0.1.19/images/add.png +0 -0
- data/rdoc/site/0.1.19/images/brick.png +0 -0
- data/rdoc/site/0.1.19/images/brick_link.png +0 -0
- data/rdoc/site/0.1.19/images/bug.png +0 -0
- data/rdoc/site/0.1.19/images/bullet_black.png +0 -0
- data/rdoc/site/0.1.19/images/bullet_toggle_minus.png +0 -0
- data/rdoc/site/0.1.19/images/bullet_toggle_plus.png +0 -0
- data/rdoc/site/0.1.19/images/date.png +0 -0
- data/rdoc/site/0.1.19/images/delete.png +0 -0
- data/rdoc/site/0.1.19/images/find.png +0 -0
- data/rdoc/site/0.1.19/images/loadingAnimation.gif +0 -0
- data/rdoc/site/0.1.19/images/macFFBgHack.png +0 -0
- data/rdoc/site/0.1.19/images/package.png +0 -0
- data/rdoc/site/0.1.19/images/page_green.png +0 -0
- data/rdoc/site/0.1.19/images/page_white_text.png +0 -0
- data/rdoc/site/0.1.19/images/page_white_width.png +0 -0
- data/rdoc/site/0.1.19/images/plugin.png +0 -0
- data/rdoc/site/0.1.19/images/ruby.png +0 -0
- data/rdoc/site/0.1.19/images/tag_blue.png +0 -0
- data/rdoc/site/0.1.19/images/tag_green.png +0 -0
- data/rdoc/site/0.1.19/images/transparent.png +0 -0
- data/rdoc/site/0.1.19/images/wrench.png +0 -0
- data/rdoc/site/0.1.19/images/wrench_orange.png +0 -0
- data/rdoc/site/0.1.19/images/zoom.png +0 -0
- data/rdoc/site/0.1.19/index.html +311 -0
- data/rdoc/site/0.1.19/js/darkfish.js +155 -0
- data/rdoc/site/0.1.19/js/jquery.js +18 -0
- data/rdoc/site/0.1.19/js/navigation.js +142 -0
- data/rdoc/site/0.1.19/js/search.js +94 -0
- data/rdoc/site/0.1.19/js/search_index.js +1 -0
- data/rdoc/site/0.1.19/js/searcher.js +228 -0
- data/rdoc/site/0.1.19/rdoc.css +543 -0
- data/rdoc/site/0.1.19/table_of_contents.html +1541 -0
- metadata +140 -11
data/lib/core/facade.rb
CHANGED
@@ -7,8 +7,9 @@ module Parallel
|
|
7
7
|
|
8
8
|
def self.included(klass)
|
9
9
|
if Nucleon.parallel?
|
10
|
-
klass.send :include, Celluloid
|
11
|
-
|
10
|
+
klass.send :include, Celluloid
|
11
|
+
klass.finalizer :parallel_finalize
|
12
|
+
end
|
12
13
|
klass.send :include, InstanceMethods
|
13
14
|
klass.extend ClassMethods
|
14
15
|
end
|
@@ -16,22 +17,62 @@ module Parallel
|
|
16
17
|
#---
|
17
18
|
|
18
19
|
module InstanceMethods
|
19
|
-
def
|
20
|
+
def parallel_finalize
|
21
|
+
# Override if needed
|
22
|
+
end
|
23
|
+
|
24
|
+
#---
|
25
|
+
|
26
|
+
def parallel(method, args, *shared_args)
|
27
|
+
results = nil
|
28
|
+
|
29
|
+
case args
|
30
|
+
when Hash
|
31
|
+
results = parallel_hash(method, args, *shared_args)
|
32
|
+
when Array, String, Symbol
|
33
|
+
results = parallel_array(method, args, *shared_args)
|
34
|
+
end
|
35
|
+
results
|
36
|
+
end
|
37
|
+
|
38
|
+
#---
|
39
|
+
|
40
|
+
def parallel_array(method, array_args, *shared_args)
|
20
41
|
results = []
|
21
|
-
|
42
|
+
array_args = [ array_args ] unless array_args.is_a?(Array)
|
22
43
|
|
23
44
|
if Nucleon.parallel?
|
24
|
-
|
45
|
+
array_args.each do |arg|
|
25
46
|
results << future.send(method, arg, *shared_args)
|
26
47
|
end
|
27
48
|
results.map { |future| future.value } # Wait for all to finish.
|
28
49
|
else
|
29
|
-
|
50
|
+
array_args.each do |arg|
|
30
51
|
results << send(method, arg, *shared_args)
|
31
52
|
end
|
32
53
|
end
|
33
54
|
results
|
34
55
|
end
|
56
|
+
|
57
|
+
#---
|
58
|
+
|
59
|
+
def parallel_hash(method, hash_args, *shared_args)
|
60
|
+
results = {}
|
61
|
+
|
62
|
+
if Nucleon.parallel?
|
63
|
+
hash_args.each do |key, value|
|
64
|
+
results[key] = future.send(method, key, value, *shared_args)
|
65
|
+
end
|
66
|
+
results.keys.each do |key| # Wait for all to finish.
|
67
|
+
results[key] = results[key].value
|
68
|
+
end
|
69
|
+
else
|
70
|
+
hash_args.each do |key, value|
|
71
|
+
results[key] = send(method, key, value, *shared_args)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
results
|
75
|
+
end
|
35
76
|
end
|
36
77
|
|
37
78
|
#---
|
@@ -95,33 +136,35 @@ module Facade
|
|
95
136
|
|
96
137
|
#---
|
97
138
|
|
98
|
-
def manager(collection, name, klass)
|
99
|
-
name
|
100
|
-
|
101
|
-
|
102
|
-
|
139
|
+
def manager(collection, name, klass, reset = false)
|
140
|
+
name = name.to_sym
|
141
|
+
actor_id = "#{klass}::#{name}".to_sym
|
142
|
+
|
143
|
+
if collection.has_key?(actor_id)
|
144
|
+
manager = parallel? ? Celluloid::Actor[actor_id] : collection[actor_id]
|
103
145
|
else
|
104
146
|
if parallel?
|
105
|
-
klass.supervise_as
|
106
|
-
manager = Celluloid::Actor[
|
147
|
+
klass.supervise_as(actor_id, actor_id, reset)
|
148
|
+
manager = Celluloid::Actor[actor_id]
|
107
149
|
else
|
108
|
-
manager = klass.new # Managers should
|
150
|
+
manager = klass.new(actor_id, reset) # Managers should have standardized initialization parameters
|
109
151
|
end
|
110
|
-
collection[
|
152
|
+
collection[actor_id] = manager
|
111
153
|
end
|
112
|
-
test_connection(manager)
|
113
|
-
manager
|
154
|
+
test_connection(actor_id, manager)
|
114
155
|
end
|
115
156
|
|
116
|
-
def test_connection(manager)
|
157
|
+
def test_connection(actor_id, manager)
|
117
158
|
if parallel?
|
118
159
|
begin
|
119
160
|
# Raise error if no test method found but retry for dead actors
|
120
161
|
manager.test_connection
|
162
|
+
|
121
163
|
rescue Celluloid::DeadActorError
|
122
164
|
retry
|
123
165
|
end
|
124
166
|
end
|
167
|
+
manager
|
125
168
|
end
|
126
169
|
|
127
170
|
#-----------------------------------------------------------------------------
|
@@ -203,98 +246,110 @@ module Facade
|
|
203
246
|
Manager.connection.namespaces
|
204
247
|
end
|
205
248
|
|
206
|
-
def define_namespace(*namespaces)
|
207
|
-
Manager.connection.namespace(*namespaces)
|
208
|
-
end
|
209
|
-
|
210
249
|
#---
|
211
250
|
|
212
|
-
def types
|
213
|
-
Manager.connection.types
|
251
|
+
def types(namespace)
|
252
|
+
Manager.connection.types(namespace)
|
214
253
|
end
|
215
254
|
|
216
|
-
def
|
217
|
-
Manager.connection.
|
255
|
+
def define_types(namespace, type_info)
|
256
|
+
Manager.connection.define_types(namespace, type_info)
|
218
257
|
end
|
219
258
|
|
220
|
-
def type_default(
|
221
|
-
Manager.connection.type_default(
|
259
|
+
def type_default(namespace, plugin_type)
|
260
|
+
Manager.connection.type_default(namespace, plugin_type)
|
222
261
|
end
|
223
262
|
|
224
263
|
#---
|
225
264
|
|
265
|
+
def load_plugins(base_dir = nil)
|
266
|
+
base_dir = base_dir.nil? ? Dir.pwd : base_dir
|
267
|
+
|
268
|
+
search_plugins = lambda do |search_dir|
|
269
|
+
lib_dir = File.join(search_dir, 'lib')
|
270
|
+
|
271
|
+
if File.directory?(lib_dir)
|
272
|
+
logger.debug("Registering plugins at #{lib_dir}")
|
273
|
+
register(lib_dir)
|
274
|
+
end
|
275
|
+
|
276
|
+
parent_search_dir = search_dir.sub(/#{File::SEPARATOR}[^#{File::SEPARATOR}]+$/, '')
|
277
|
+
search_plugins.call(parent_search_dir) unless parent_search_dir.split(File::SEPARATOR).empty?
|
278
|
+
end
|
279
|
+
|
280
|
+
search_plugins.call(base_dir)
|
281
|
+
end
|
282
|
+
|
226
283
|
def register(base_path, &code)
|
227
284
|
Manager.connection.register(base_path, &code)
|
228
285
|
Manager.connection.autoload
|
229
286
|
end
|
230
287
|
|
231
|
-
def loaded_plugins(
|
232
|
-
Manager.connection.loaded_plugins(
|
288
|
+
def loaded_plugins(namespace = nil, plugin_type = nil, provider = nil)
|
289
|
+
Manager.connection.loaded_plugins(namespace, plugin_type, provider)
|
233
290
|
end
|
234
291
|
|
235
292
|
#---
|
236
293
|
|
237
|
-
def active_plugins(
|
238
|
-
Manager.connection.
|
294
|
+
def active_plugins(namespace = nil, plugin_type = nil, provider = nil)
|
295
|
+
Manager.connection.active_plugins(namespace, plugin_type, provider)
|
239
296
|
end
|
240
297
|
|
241
298
|
#---
|
242
299
|
|
243
|
-
def plugin(
|
244
|
-
Manager.connection.load(
|
300
|
+
def plugin(namespace, plugin_type, provider, options = {})
|
301
|
+
Manager.connection.load(namespace, plugin_type, provider, options)
|
245
302
|
end
|
246
303
|
|
247
304
|
#---
|
248
305
|
|
249
|
-
def plugins(
|
250
|
-
Manager.connection.load_multiple(
|
306
|
+
def plugins(namespace, plugin_type, data, build_hash = false, keep_array = false)
|
307
|
+
Manager.connection.load_multiple(namespace, plugin_type, data, build_hash, keep_array)
|
251
308
|
end
|
252
309
|
|
253
310
|
#---
|
254
311
|
|
255
|
-
def create_plugin(
|
256
|
-
Manager.connection.create(
|
312
|
+
def create_plugin(namespace, plugin_type, provider, options = {})
|
313
|
+
Manager.connection.create(namespace, plugin_type, provider, options)
|
257
314
|
end
|
258
315
|
|
259
316
|
#---
|
260
317
|
|
261
|
-
def get_plugin(
|
262
|
-
Manager.connection.get(
|
318
|
+
def get_plugin(namespace, plugin_type, plugin_name)
|
319
|
+
Manager.connection.get(namespace, plugin_type, plugin_name)
|
263
320
|
end
|
264
321
|
|
265
322
|
#---
|
266
323
|
|
267
|
-
def
|
268
|
-
Manager.connection.
|
324
|
+
def remove_plugin_by_name(namespace, plugin_type, plugin_instance_name)
|
325
|
+
Manager.connection.remove_by_name(namespace, plugin_type, plugin_instance_name)
|
269
326
|
end
|
270
327
|
|
271
|
-
|
272
|
-
|
273
|
-
def plugin_class(type)
|
274
|
-
Manager.connection.plugin_class(type)
|
328
|
+
def remove_plugin(plugin)
|
329
|
+
Manager.connection.remove(plugin)
|
275
330
|
end
|
276
331
|
|
277
332
|
#---
|
278
333
|
|
279
|
-
def
|
280
|
-
Manager.connection.
|
334
|
+
def plugin_class(namespace, plugin_type)
|
335
|
+
Manager.connection.plugin_class(namespace, plugin_type)
|
281
336
|
end
|
282
337
|
|
283
338
|
#-----------------------------------------------------------------------------
|
284
339
|
# Core plugin type facade
|
285
340
|
|
286
341
|
def extension(provider)
|
287
|
-
plugin(:extension, provider, {})
|
342
|
+
plugin(:nucleon, :extension, provider, {})
|
288
343
|
end
|
289
344
|
|
290
345
|
#---
|
291
346
|
|
292
347
|
def action(provider, options)
|
293
|
-
plugin(:action, provider, options)
|
348
|
+
plugin(:nucleon, :action, provider, options)
|
294
349
|
end
|
295
350
|
|
296
351
|
def actions(data, build_hash = false, keep_array = false)
|
297
|
-
plugins(:action, data, build_hash, keep_array)
|
352
|
+
plugins(:nucleon, :action, data, build_hash, keep_array)
|
298
353
|
end
|
299
354
|
|
300
355
|
def action_config(provider)
|
@@ -313,55 +368,72 @@ module Facade
|
|
313
368
|
Plugin::Action.exec_cli(provider, args, quiet, name)
|
314
369
|
end
|
315
370
|
|
371
|
+
def search_actions(args)
|
372
|
+
action_info = Plugin::Action.search_actions(args)
|
373
|
+
|
374
|
+
action_components = action_info[:components]
|
375
|
+
action = action_info[:actions]
|
376
|
+
|
377
|
+
action_components.each do |component|
|
378
|
+
args.shift
|
379
|
+
end
|
380
|
+
|
381
|
+
[ action, action_components, args ]
|
382
|
+
end
|
383
|
+
|
384
|
+
def action_help(action = nil, extended_help = false)
|
385
|
+
Plugin::Action.action_help(action, extended_help)
|
386
|
+
end
|
387
|
+
|
316
388
|
#---
|
317
389
|
|
318
390
|
def project(options, provider = nil)
|
319
|
-
plugin(:project, provider, options)
|
391
|
+
plugin(:nucleon, :project, provider, options)
|
320
392
|
end
|
321
393
|
|
322
394
|
def projects(data, build_hash = false, keep_array = false)
|
323
|
-
plugins(:project, data, build_hash, keep_array)
|
395
|
+
plugins(:nucleon, :project, data, build_hash, keep_array)
|
324
396
|
end
|
325
397
|
|
326
398
|
#-----------------------------------------------------------------------------
|
327
399
|
# Utility plugin type facade
|
328
400
|
|
329
401
|
def command(options, provider = nil)
|
330
|
-
plugin(:command, provider, options)
|
402
|
+
plugin(:nucleon, :command, provider, options)
|
331
403
|
end
|
332
404
|
|
333
405
|
def commands(data, build_hash = false, keep_array = false)
|
334
|
-
plugins(:command, data, build_hash, keep_array)
|
406
|
+
plugins(:nucleon, :command, data, build_hash, keep_array)
|
335
407
|
end
|
336
408
|
|
337
409
|
#---
|
338
410
|
|
339
411
|
def event(options, provider = nil)
|
340
|
-
plugin(:event, provider, options)
|
412
|
+
plugin(:nucleon, :event, provider, options)
|
341
413
|
end
|
342
414
|
|
343
415
|
def events(data, build_hash = false, keep_array = false)
|
344
|
-
plugins(:event, data, build_hash, keep_array)
|
416
|
+
plugins(:nucleon, :event, data, build_hash, keep_array)
|
345
417
|
end
|
346
418
|
|
347
419
|
#---
|
348
420
|
|
349
421
|
def template(options, provider = nil)
|
350
|
-
plugin(:template, provider, options)
|
422
|
+
plugin(:nucleon, :template, provider, options)
|
351
423
|
end
|
352
424
|
|
353
425
|
def templates(data, build_hash = false, keep_array = false)
|
354
|
-
plugins(:template, data, build_hash, keep_array)
|
426
|
+
plugins(:nucleon, :template, data, build_hash, keep_array)
|
355
427
|
end
|
356
428
|
|
357
429
|
#---
|
358
430
|
|
359
431
|
def translator(options, provider = nil)
|
360
|
-
plugin(:translator, provider, options)
|
432
|
+
plugin(:nucleon, :translator, provider, options)
|
361
433
|
end
|
362
434
|
|
363
435
|
def translators(data, build_hash = false, keep_array = false)
|
364
|
-
plugins(:translator, data, build_hash, keep_array)
|
436
|
+
plugins(:nucleon, :translator, data, build_hash, keep_array)
|
365
437
|
end
|
366
438
|
|
367
439
|
#-----------------------------------------------------------------------------
|
@@ -433,62 +505,41 @@ module Facade
|
|
433
505
|
#---
|
434
506
|
|
435
507
|
def executable(args, name = 'nucleon') #ARGV
|
436
|
-
Signal.trap("INT") { exit 1 }
|
437
|
-
|
438
508
|
logger.info("`#{name}` invoked: #{args.inspect}")
|
439
509
|
|
440
510
|
$stdout.sync = true
|
441
511
|
$stderr.sync = true
|
442
512
|
|
443
513
|
exit_status = nil
|
514
|
+
|
515
|
+
# We need to catch this early.
|
516
|
+
Util::Console.use_colors = ! args.include?("--no-color")
|
517
|
+
args = args - [ "--no-color", "--color" ]
|
444
518
|
|
445
519
|
begin
|
446
520
|
logger.debug("Beginning execution run")
|
447
521
|
|
448
|
-
|
522
|
+
load_plugins
|
523
|
+
|
524
|
+
arg_components = Util::CLI::Parser.split(args, cyan(name) + yellow(" <action components> [<arg> ...]"))
|
449
525
|
main_command = arg_components.shift
|
450
|
-
sub_command = arg_components.shift
|
451
|
-
sub_args = arg_components
|
452
526
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
end
|
458
|
-
|
459
|
-
if main_command.processed && sub_command
|
460
|
-
exit_status = action_cli(sub_command, sub_args, false, name)
|
527
|
+
action, action_components, args = search_actions(args)
|
528
|
+
|
529
|
+
if main_command.processed && action.is_a?(Hash)
|
530
|
+
exit_status = action_cli(action[:provider], args, false, name)
|
461
531
|
else
|
462
532
|
puts I18n.t('nucleon.core.exec.help.usage') + ': ' + main_command.help + "\n"
|
463
|
-
puts I18n.t('nucleon.core.exec.help.header') + ":\n
|
533
|
+
puts I18n.t('nucleon.core.exec.help.header') + ":\n"
|
464
534
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
loaded_plugins(:action).each do |provider, data|
|
469
|
-
namespace = data[:namespace]
|
470
|
-
|
471
|
-
help_data[namespace] = {} unless help_data.has_key?(namespace)
|
472
|
-
help_data[namespace][provider] = data
|
473
|
-
end
|
535
|
+
action = main_command.processed ? action : nil
|
536
|
+
puts action_help(action, args.include?("--help"))
|
474
537
|
|
475
|
-
|
476
|
-
actions.each do |provider, data|
|
477
|
-
if extended_help
|
478
|
-
help_text = action(provider, { :args => [ '-h' ], :quiet => true }).help
|
479
|
-
else
|
480
|
-
help_text = action(provider, { :settings => {}, :quiet => true }).help
|
481
|
-
end
|
482
|
-
puts sprintf(" %-15s : %s\n", namespace, help_text)
|
483
|
-
end
|
484
|
-
puts "\n"
|
485
|
-
end
|
486
|
-
|
487
|
-
puts "\n" + I18n.t('nucleon.core.exec.help.footer', { :name => name }) + "\n\n"
|
538
|
+
puts "\n" + I18n.t('nucleon.core.exec.help.footer', { :command => cyan(name) + yellow(" <action> -h") }) + "\n\n"
|
488
539
|
exit_status = code.help_wanted
|
489
540
|
end
|
490
541
|
|
491
|
-
rescue
|
542
|
+
rescue => error
|
492
543
|
logger.error("Nucleon executable experienced an error:")
|
493
544
|
logger.error(error.inspect)
|
494
545
|
logger.error(error.message)
|
@@ -499,6 +550,7 @@ module Facade
|
|
499
550
|
exit_status = error.status_code if error.respond_to?(:status_code)
|
500
551
|
exit_status = code.unknown_status if exit_status.nil?
|
501
552
|
end
|
553
|
+
|
502
554
|
exit_status
|
503
555
|
end
|
504
556
|
|
data/lib/core/manager.rb
CHANGED
@@ -6,28 +6,40 @@ class Manager
|
|
6
6
|
|
7
7
|
#-----------------------------------------------------------------------------
|
8
8
|
|
9
|
-
@@supervisors
|
9
|
+
@@supervisors = {}
|
10
|
+
@@environments = {}
|
10
11
|
|
11
12
|
#-----------------------------------------------------------------------------
|
12
13
|
# Plugin manager interface
|
13
14
|
|
14
|
-
def self.connection(name = :core)
|
15
|
-
Nucleon.manager(@@supervisors, name, self)
|
15
|
+
def self.connection(name = :core, reset = false)
|
16
|
+
Nucleon.manager(@@supervisors, name, self, reset)
|
16
17
|
end
|
17
18
|
|
18
19
|
#---
|
19
20
|
|
20
|
-
def initialize
|
21
|
-
@logger
|
21
|
+
def initialize(actor_id, reset)
|
22
|
+
@logger = Nucleon.logger
|
23
|
+
@actor_id = actor_id
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@plugins = {}
|
25
|
+
if reset || ! @@environments[@actor_id]
|
26
|
+
@@environments[@actor_id] = Environment.new
|
27
|
+
end
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
#---
|
31
|
+
|
32
|
+
def parallel_finalize
|
33
|
+
active_plugins.each do |namespace, namespace_plugins|
|
34
|
+
namespace_plugins.each do |plugin_type, type_plugins|
|
35
|
+
type_plugins.each do |instance_name, plugin|
|
36
|
+
remove(plugin)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#---
|
31
43
|
|
32
44
|
attr_reader :logger
|
33
45
|
|
@@ -39,93 +51,81 @@ class Manager
|
|
39
51
|
|
40
52
|
#---
|
41
53
|
|
42
|
-
def
|
43
|
-
|
54
|
+
def test_connection
|
55
|
+
true
|
44
56
|
end
|
45
57
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
58
|
+
#-----------------------------------------------------------------------------
|
59
|
+
# Plugin model accessors / modifiers
|
60
|
+
|
61
|
+
def namespaces
|
62
|
+
@@environments[@actor_id].namespaces
|
50
63
|
end
|
51
64
|
|
52
65
|
#---
|
53
66
|
|
54
|
-
def types
|
55
|
-
@
|
67
|
+
def types(namespace)
|
68
|
+
@@environments[@actor_id].plugin_types(namespace)
|
56
69
|
end
|
57
70
|
|
58
|
-
|
71
|
+
def define_type(namespace, plugin_type, default_provider)
|
72
|
+
@@environments[@actor_id].define_plugin_type(namespace, plugin_type, default_provider)
|
73
|
+
end
|
59
74
|
|
60
|
-
def
|
61
|
-
@
|
75
|
+
def define_types(namespace, type_info)
|
76
|
+
@@environments[@actor_id].define_plugin_types(namespace, type_info)
|
62
77
|
end
|
63
78
|
|
64
|
-
|
79
|
+
def type_defined?(namespace, plugin_type)
|
80
|
+
@@environments[@actor_id].plugin_type_defined?(namespace, plugin_type)
|
81
|
+
end
|
65
82
|
|
66
|
-
def
|
67
|
-
|
68
|
-
type = type.to_sym if type
|
69
|
-
provider = provider.to_sym if provider
|
70
|
-
|
71
|
-
if type && @load_info.has_key?(type)
|
72
|
-
if provider && @load_info.has_key?(provider)
|
73
|
-
results = @load_info[type][provider]
|
74
|
-
else
|
75
|
-
results = @load_info[type]
|
76
|
-
end
|
77
|
-
elsif ! type
|
78
|
-
results = @load_info
|
79
|
-
end
|
80
|
-
results
|
83
|
+
def type_default(namespace, plugin_type)
|
84
|
+
@@environments[@actor_id].plugin_type_default(namespace, plugin_type)
|
81
85
|
end
|
82
|
-
|
86
|
+
|
83
87
|
#---
|
84
88
|
|
85
|
-
def
|
86
|
-
|
87
|
-
|
88
|
-
provider = provider.to_sym if provider
|
89
|
-
|
90
|
-
if type && @plugins.has_key?(type)
|
91
|
-
if provider && ! @plugins[type].keys.empty?
|
92
|
-
@plugins[type].each do |instance_name, plugin|
|
93
|
-
plugin = @plugins[type][instance_name]
|
94
|
-
results[instance_name] = plugin if plugin.plugin_provider == provider
|
95
|
-
end
|
96
|
-
else
|
97
|
-
results = @plugins[type]
|
98
|
-
end
|
99
|
-
elsif ! type
|
100
|
-
results = @plugins
|
101
|
-
end
|
102
|
-
results
|
103
|
-
end
|
89
|
+
def loaded_plugin(namespace, plugin_type, provider)
|
90
|
+
@@environments[@actor_id].loaded_plugin(namespace, plugin_type, provider)
|
91
|
+
end
|
104
92
|
|
105
|
-
|
106
|
-
|
93
|
+
def loaded_plugins(namespace = nil, plugin_type = nil, provider = nil)
|
94
|
+
@@environments[@actor_id].loaded_plugins(namespace, plugin_type, provider)
|
95
|
+
end
|
107
96
|
|
108
|
-
def
|
109
|
-
|
97
|
+
def define_plugin(namespace, plugin_type, base_path, file, &code)
|
98
|
+
@@environments[@actor_id].define_plugin(namespace, plugin_type, base_path, file, &code)
|
99
|
+
end
|
100
|
+
|
101
|
+
def plugin_has_provider?(namespace, plugin_type, provider)
|
102
|
+
@@environments[@actor_id].plugin_has_provider?(namespace, plugin_type, provider)
|
110
103
|
end
|
111
104
|
|
112
105
|
#---
|
113
106
|
|
107
|
+
def active_plugins(namespace = nil, plugin_type = nil, provider = nil)
|
108
|
+
@@environments[@actor_id].active_plugins(namespace, plugin_type, provider)
|
109
|
+
end
|
110
|
+
|
111
|
+
#-----------------------------------------------------------------------------
|
112
|
+
# Plugin registration / initialization
|
113
|
+
|
114
114
|
def reload(core = false, &code)
|
115
115
|
logger.info("Loading Nucleon plugins at #{Time.now}")
|
116
116
|
|
117
117
|
if core
|
118
118
|
Celluloid.logger = logger if Nucleon.parallel?
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
120
|
+
define_types :nucleon, {
|
121
|
+
:extension => nil, # Core
|
122
|
+
:action => :update, # Core
|
123
|
+
:project => :git, # Core
|
124
|
+
:command => :bash, # Core
|
125
|
+
:event => :regex, # Utility
|
126
|
+
:template => :json, # Utility
|
127
|
+
:translator => :json # Utility
|
128
|
+
}
|
129
129
|
end
|
130
130
|
|
131
131
|
# Allow block level namespace and type registration
|
@@ -137,21 +137,6 @@ class Manager
|
|
137
137
|
|
138
138
|
#---
|
139
139
|
|
140
|
-
def define_type(type_info)
|
141
|
-
if type_info.is_a?(Hash)
|
142
|
-
logger.info("Defining plugin types at #{Time.now}")
|
143
|
-
|
144
|
-
type_info.each do |type, default_provider|
|
145
|
-
logger.debug("Mapping plugin type #{type} to default provider #{default_provider}")
|
146
|
-
@types[type.to_sym] = default_provider
|
147
|
-
end
|
148
|
-
else
|
149
|
-
logger.warn("Defined types must be specified as a hash to be registered properly")
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
#---
|
154
|
-
|
155
140
|
def load_plugins(core = false, &code)
|
156
141
|
if core
|
157
142
|
# Register core plugins
|
@@ -196,7 +181,7 @@ class Manager
|
|
196
181
|
logger.info("Loading directories from #{base_path} at #{Time.now}")
|
197
182
|
Dir.entries(base_path).each do |path|
|
198
183
|
unless path.match(/^\.\.?$/)
|
199
|
-
register_type(namespace, base_path, path, &code) if
|
184
|
+
register_type(namespace, base_path, path, &code) if type_defined?(namespace, path)
|
200
185
|
end
|
201
186
|
end
|
202
187
|
end
|
@@ -211,70 +196,50 @@ class Manager
|
|
211
196
|
if File.directory?(base_directory)
|
212
197
|
logger.info("Registering #{base_directory} at #{Time.now}")
|
213
198
|
|
214
|
-
Dir.glob(File.join(base_directory, '*.rb')).each do |file|
|
215
|
-
|
199
|
+
Dir.glob(File.join(base_directory, '**', '*.rb')).each do |file|
|
200
|
+
define_plugin(namespace, plugin_type, base_directory, file, &code)
|
216
201
|
end
|
217
202
|
end
|
218
203
|
end
|
219
204
|
protected :register_type
|
220
205
|
|
221
|
-
#---
|
222
|
-
|
223
|
-
def add_build_info(namespace, type, file, &code)
|
224
|
-
type = type.to_sym
|
225
|
-
|
226
|
-
@load_info[type] = {} unless @load_info.has_key?(type)
|
227
|
-
|
228
|
-
components = file.split(File::SEPARATOR)
|
229
|
-
provider = components.pop.sub(/\.rb/, '').to_sym
|
230
|
-
directory = components.join(File::SEPARATOR)
|
231
|
-
|
232
|
-
logger.info("Loading nucleon #{type} plugin #{provider} at #{Time.now}")
|
233
|
-
|
234
|
-
unless @load_info[type].has_key?(provider)
|
235
|
-
data = {
|
236
|
-
:namespace => namespace,
|
237
|
-
:type => type,
|
238
|
-
:provider => provider,
|
239
|
-
:directory => directory,
|
240
|
-
:file => file
|
241
|
-
}
|
242
|
-
code.call(data) if code
|
243
|
-
|
244
|
-
logger.debug("Plugin #{type} loaded: #{data.inspect}")
|
245
|
-
@load_info[type][provider] = data
|
246
|
-
end
|
247
|
-
end
|
248
|
-
protected :add_build_info
|
249
|
-
|
250
206
|
#---
|
251
207
|
|
252
208
|
def autoload
|
253
209
|
logger.info("Autoloading registered plugins at #{Time.now}")
|
254
210
|
|
255
|
-
|
256
|
-
|
211
|
+
load_info = loaded_plugins
|
212
|
+
|
213
|
+
load_info.keys.each do |namespace|
|
214
|
+
load_info[namespace].keys.each do |plugin_type|
|
215
|
+
logger.debug("Autoloading type: #{plugin_type}")
|
257
216
|
|
258
|
-
|
259
|
-
|
217
|
+
load_info[namespace][plugin_type].each do |provider, plugin|
|
218
|
+
logger.debug("Autoloading provider #{provider} at #{plugin[:directory]}")
|
260
219
|
|
261
|
-
|
220
|
+
require plugin[:file]
|
221
|
+
|
222
|
+
load_info[namespace][plugin_type][provider][:class] = class_const(plugin[:class_components])
|
223
|
+
logger.debug("Updated #{plugin_type} #{provider} load info")
|
262
224
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
225
|
+
# Make sure extensions are listening from the time they are loaded
|
226
|
+
if plugin[:namespace] == :nucleon && plugin_type == :extension
|
227
|
+
# Create a persistent instance
|
228
|
+
load(plugin[:namespace], :extension, provider, { :name => provider })
|
229
|
+
end
|
230
|
+
end
|
268
231
|
end
|
269
232
|
end
|
270
233
|
end
|
271
234
|
|
272
|
-
|
235
|
+
#-----------------------------------------------------------------------------
|
236
|
+
# Plugin workflow
|
273
237
|
|
274
|
-
def load_base(
|
275
|
-
logger.info("Fetching plugin #{
|
238
|
+
def load_base(namespace, plugin_type, provider, options = {})
|
239
|
+
logger.info("Fetching plugin #{namespace} #{plugin_type} provider #{provider} at #{Time.now}")
|
276
240
|
|
277
|
-
|
241
|
+
type_info = loaded_plugin(namespace, plugin_type, provider)
|
242
|
+
options = translate_type(type_info, options)
|
278
243
|
config = Config.ensure(options)
|
279
244
|
name = config.get(:name, nil)
|
280
245
|
ensure_new = config.delete(:new, false)
|
@@ -282,7 +247,7 @@ class Manager
|
|
282
247
|
if name
|
283
248
|
logger.debug("Looking up existing instance of #{name}")
|
284
249
|
|
285
|
-
if existing_instance = get(
|
250
|
+
if existing_instance = get(namespace, plugin_type, name)
|
286
251
|
unless ensure_new
|
287
252
|
config.export.each do |property_name, value|
|
288
253
|
unless [ :name, :meta ].include?(property_name)
|
@@ -291,38 +256,38 @@ class Manager
|
|
291
256
|
end
|
292
257
|
existing_instance.normalize(true)
|
293
258
|
|
294
|
-
logger.debug("Using existing instance of #{
|
259
|
+
logger.debug("Using existing instance of #{plugin_type}, #{name}")
|
295
260
|
return existing_instance
|
296
261
|
end
|
297
262
|
end
|
298
263
|
end
|
299
|
-
create(
|
264
|
+
create(namespace, plugin_type, provider, config)
|
300
265
|
end
|
301
266
|
|
302
267
|
#---
|
303
268
|
|
304
|
-
def load(
|
305
|
-
default_provider = type_default(
|
269
|
+
def load(namespace, plugin_type, provider = nil, options = {})
|
270
|
+
default_provider = type_default(namespace, plugin_type)
|
306
271
|
|
307
272
|
# Allow options to override provider
|
308
273
|
config = Config.ensure(options)
|
309
274
|
provider = config.delete(:provider, provider)
|
310
275
|
provider = default_provider unless provider
|
311
276
|
|
312
|
-
load_base(
|
277
|
+
load_base(namespace, plugin_type, provider, config)
|
313
278
|
end
|
314
279
|
|
315
280
|
#---
|
316
281
|
|
317
|
-
def load_multiple(
|
318
|
-
logger.info("Fetching multiple plugins of #{
|
282
|
+
def load_multiple(namespace, plugin_type, data, build_hash = false, keep_array = false)
|
283
|
+
logger.info("Fetching multiple plugins of #{plugin_type} at #{Time.now}")
|
319
284
|
|
320
285
|
group = ( build_hash ? {} : [] )
|
321
|
-
klass = plugin_class(
|
322
|
-
data = klass.build_info(
|
286
|
+
klass = plugin_class(namespace, plugin_type)
|
287
|
+
data = klass.build_info(namespace, plugin_type, data) if klass.respond_to?(:build_info)
|
323
288
|
|
324
289
|
data.each do |options|
|
325
|
-
if plugin = load(
|
290
|
+
if plugin = load(namespace, plugin_type, options[:provider], options)
|
326
291
|
if build_hash
|
327
292
|
group[plugin.plugin_name] = plugin
|
328
293
|
else
|
@@ -336,69 +301,46 @@ class Manager
|
|
336
301
|
|
337
302
|
#---
|
338
303
|
|
339
|
-
def create(
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
unless @types.has_key?(type)
|
344
|
-
logger.warn("Plugin type #{type} creation requested but it has not been registered yet")
|
345
|
-
return nil
|
346
|
-
end
|
347
|
-
|
348
|
-
info = @load_info[type][provider] if Util::Data.exists?(@load_info, [ type, provider ])
|
349
|
-
|
350
|
-
if info
|
351
|
-
logger.debug("Plugin information for #{provider} #{type} found.")
|
352
|
-
|
353
|
-
instance_name = "#{provider}_" + Nucleon.sha1(options)
|
354
|
-
options = translate(info[:namespace], type, provider, options)
|
355
|
-
|
356
|
-
@plugins[type] = {} unless @plugins.has_key?(type)
|
304
|
+
def create(namespace, plugin_type, provider, options = {})
|
305
|
+
@@environments[@actor_id].create_plugin(namespace, plugin_type, provider, options) do |type_info, plugin_options|
|
306
|
+
logger.info("Creating new plugin #{provider} #{plugin_type}")
|
357
307
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
logger.info("Creating new plugin #{provider} #{type}")
|
363
|
-
|
364
|
-
plugin = info[:class].new(type, provider, options)
|
365
|
-
|
366
|
-
@plugins[type][instance_name] = plugin
|
367
|
-
end
|
368
|
-
return @plugins[type][instance_name]
|
308
|
+
plugin_options = translate(type_info, plugin_options)
|
309
|
+
plugin_options[:meta] = Config.new(type_info).import(Util::Data.hash(plugin_options[:meta]))
|
310
|
+
plugin_options
|
369
311
|
end
|
370
|
-
|
371
|
-
logger.warn("Plugin information cannot be found for plugin #{type} #{provider}")
|
372
|
-
nil
|
373
312
|
end
|
374
313
|
|
375
314
|
#---
|
376
315
|
|
377
|
-
def get(
|
378
|
-
|
379
|
-
|
380
|
-
if @plugins.has_key?(type)
|
381
|
-
@plugins[type].each do |instance_name, plugin|
|
382
|
-
if plugin.plugin_name.to_s == name.to_s
|
383
|
-
logger.debug("Plugin #{type} #{name} found")
|
384
|
-
return plugin
|
385
|
-
end
|
386
|
-
end
|
387
|
-
end
|
388
|
-
logger.debug("Plugin #{type} #{name} not found")
|
389
|
-
nil
|
316
|
+
def get(namespace, plugin_type, plugin_name)
|
317
|
+
@@environments[@actor_id].get_plugin(namespace, plugin_type, plugin_name)
|
390
318
|
end
|
391
319
|
|
392
320
|
#---
|
393
321
|
|
322
|
+
def remove_by_name(namespace, plugin_type, plugin_instance_name)
|
323
|
+
active_instances = active_plugins(namespace, plugin_type)
|
324
|
+
|
325
|
+
if active_instances.has_key?(plugin_instance_name)
|
326
|
+
@@environments[@actor_id].remove_plugin(namespace, plugin_type, plugin_instance_name) do |plugin|
|
327
|
+
logger.debug("Removing #{plugin_type} #{plugin_instance_name}")
|
328
|
+
|
329
|
+
if plugin.respond_to?(:terminate) # For Celluloid plugins
|
330
|
+
plugin.terminate
|
331
|
+
else
|
332
|
+
plugin.remove_plugin
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
394
338
|
def remove(plugin)
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
else
|
401
|
-
logger.warn("Cannot remove plugin: #{plugin.inspect}")
|
339
|
+
begin # TODO: Figure out what do do about the plugin proxy being terminated before respond_to? method called.
|
340
|
+
if plugin && plugin.respond_to?(:plugin_type)
|
341
|
+
remove_by_name(plugin.plugin_namespace, plugin.plugin_type, plugin.plugin_instance_name)
|
342
|
+
end
|
343
|
+
rescue
|
402
344
|
end
|
403
345
|
end
|
404
346
|
|
@@ -408,11 +350,9 @@ class Manager
|
|
408
350
|
def exec(method, options = {})
|
409
351
|
results = nil
|
410
352
|
|
411
|
-
|
412
|
-
logger.hook("Executing extension hook #{Nucleon.blue(method)} at #{Nucleon.green(Time.now.to_s)}")
|
413
|
-
end
|
353
|
+
logger.info("Executing extension hook #{Nucleon.blue(method)} at #{Nucleon.green(Time.now.to_s)}")
|
414
354
|
|
415
|
-
extensions =
|
355
|
+
extensions = active_plugins(:nucleon, :extension)
|
416
356
|
|
417
357
|
extensions.each do |name, plugin|
|
418
358
|
provider = plugin.plugin_provider
|
@@ -424,7 +364,7 @@ class Manager
|
|
424
364
|
results = {} if results.nil?
|
425
365
|
|
426
366
|
result = plugin.send(method, options)
|
427
|
-
logger.info("Completed hook #{method} at #{Time.now}
|
367
|
+
logger.info("Completed hook #{method} at #{Time.now}")
|
428
368
|
|
429
369
|
if block_given?
|
430
370
|
results[provider] = yield(:process, result)
|
@@ -452,7 +392,7 @@ class Manager
|
|
452
392
|
def config(type, options = {})
|
453
393
|
config = Config.ensure(options)
|
454
394
|
|
455
|
-
logger.debug("Generating #{type} extended configuration
|
395
|
+
logger.debug("Generating #{type} extended configuration")
|
456
396
|
|
457
397
|
exec("#{type}_config", Config.new(config.export)) do |op, data|
|
458
398
|
if op == :reduce
|
@@ -465,8 +405,6 @@ class Manager
|
|
465
405
|
end
|
466
406
|
end
|
467
407
|
config.delete(:extension_type)
|
468
|
-
|
469
|
-
logger.debug("Final extended configuration: #{config.export.inspect}")
|
470
408
|
config
|
471
409
|
end
|
472
410
|
|
@@ -475,7 +413,7 @@ class Manager
|
|
475
413
|
def check(method, options = {})
|
476
414
|
config = Config.ensure(options)
|
477
415
|
|
478
|
-
logger.debug("Checking extension #{method}
|
416
|
+
logger.debug("Checking extension #{method}")
|
479
417
|
|
480
418
|
success = exec(method, config.import({ :extension_type => :check })) do |op, data|
|
481
419
|
if op == :reduce
|
@@ -496,7 +434,7 @@ class Manager
|
|
496
434
|
def value(method, value, options = {})
|
497
435
|
config = Config.ensure(options)
|
498
436
|
|
499
|
-
logger.debug("Setting extension #{method} value
|
437
|
+
logger.debug("Setting extension #{method} value")
|
500
438
|
|
501
439
|
exec(method, config.import({ :value => value, :extension_type => :value })) do |op, data|
|
502
440
|
if op == :process
|
@@ -530,72 +468,45 @@ class Manager
|
|
530
468
|
#-----------------------------------------------------------------------------
|
531
469
|
# Utilities
|
532
470
|
|
533
|
-
def translate_type(
|
534
|
-
|
535
|
-
|
471
|
+
def translate_type(type_info, options)
|
472
|
+
if type_info
|
473
|
+
klass = plugin_class(type_info[:namespace], type_info[:type])
|
474
|
+
logger.debug("Executing option translation for: #{klass.inspect}")
|
536
475
|
|
537
|
-
|
476
|
+
options = klass.send(:translate, options) if klass.respond_to?(:translate)
|
477
|
+
end
|
538
478
|
options
|
539
479
|
end
|
540
480
|
|
541
481
|
#---
|
542
482
|
|
543
|
-
def translate(
|
544
|
-
|
545
|
-
|
483
|
+
def translate(type_info, options)
|
484
|
+
if type_info
|
485
|
+
klass = type_info[:class]
|
486
|
+
|
487
|
+
logger.debug("Executing option translation for: #{klass.inspect}")
|
546
488
|
|
547
|
-
|
489
|
+
options = klass.send(:translate, options) if klass.respond_to?(:translate)
|
490
|
+
end
|
548
491
|
options
|
549
492
|
end
|
550
493
|
|
551
494
|
#---
|
552
495
|
|
553
496
|
def class_name(name, separator = '::', want_array = FALSE)
|
554
|
-
|
555
|
-
|
556
|
-
case name
|
557
|
-
when String, Symbol
|
558
|
-
components = name.to_s.split(separator)
|
559
|
-
when Array
|
560
|
-
components = name
|
561
|
-
end
|
562
|
-
|
563
|
-
components.collect! do |value|
|
564
|
-
value = value.to_s.strip
|
565
|
-
value[0] = value.capitalize[0] if value =~ /^[a-z]/
|
566
|
-
value
|
567
|
-
end
|
568
|
-
|
569
|
-
if want_array
|
570
|
-
return components
|
571
|
-
end
|
572
|
-
components.join(separator)
|
497
|
+
@@environments[@actor_id].class_name(name, separator, want_array)
|
573
498
|
end
|
574
499
|
|
575
500
|
#---
|
576
501
|
|
577
502
|
def class_const(name, separator = '::')
|
578
|
-
|
579
|
-
constant = Object
|
580
|
-
|
581
|
-
components.each do |component|
|
582
|
-
constant = constant.const_defined?(component) ?
|
583
|
-
constant.const_get(component) :
|
584
|
-
constant.const_missing(component)
|
585
|
-
end
|
586
|
-
constant
|
587
|
-
end
|
588
|
-
|
589
|
-
#---
|
590
|
-
|
591
|
-
def plugin_class(type)
|
592
|
-
class_const([ :nucleon, :plugin, type ])
|
503
|
+
@@environments[@actor_id].class_const(name, separator)
|
593
504
|
end
|
594
505
|
|
595
506
|
#---
|
596
507
|
|
597
|
-
def
|
598
|
-
|
508
|
+
def plugin_class(namespace, plugin_type)
|
509
|
+
@@environments[@actor_id].plugin_class(namespace, plugin_type)
|
599
510
|
end
|
600
511
|
end
|
601
512
|
end
|