nucleon 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/Gemfile +4 -8
  2. data/Gemfile.lock +0 -28
  3. data/README.rdoc +13 -5
  4. data/Rakefile +9 -1
  5. data/VERSION +1 -1
  6. data/bin/nucleon +55 -0
  7. data/lib/core/codes.rb +107 -0
  8. data/lib/core/config/collection.rb +57 -0
  9. data/lib/core/config/options.rb +70 -0
  10. data/lib/core/config.rb +342 -0
  11. data/lib/core/core.rb +54 -0
  12. data/lib/core/errors.rb +84 -0
  13. data/lib/core/facade.rb +283 -0
  14. data/lib/core/gems.rb +80 -0
  15. data/lib/core/manager.rb +594 -0
  16. data/lib/core/mixin/action/commit.rb +58 -0
  17. data/lib/core/mixin/action/project.rb +53 -0
  18. data/lib/core/mixin/action/push.rb +52 -0
  19. data/lib/core/mixin/config/collection.rb +53 -0
  20. data/lib/core/mixin/config/options.rb +39 -0
  21. data/lib/core/mixin/macro/object_interface.rb +361 -0
  22. data/lib/core/mixin/macro/plugin_interface.rb +380 -0
  23. data/lib/core/mixin/settings.rb +46 -0
  24. data/lib/core/mixin/sub_config.rb +148 -0
  25. data/lib/core/mod/hash.rb +29 -0
  26. data/lib/core/plugin/action.rb +371 -0
  27. data/lib/core/plugin/base.rb +313 -0
  28. data/lib/core/plugin/command.rb +98 -0
  29. data/lib/core/plugin/event.rb +53 -0
  30. data/lib/core/plugin/extension.rb +12 -0
  31. data/lib/core/plugin/project.rb +890 -0
  32. data/lib/core/plugin/template.rb +80 -0
  33. data/lib/core/plugin/translator.rb +38 -0
  34. data/lib/core/util/cli.rb +353 -0
  35. data/lib/core/util/console.rb +237 -0
  36. data/lib/core/util/data.rb +404 -0
  37. data/lib/core/util/disk.rb +114 -0
  38. data/lib/core/util/git.rb +43 -0
  39. data/lib/core/util/liquid.rb +17 -0
  40. data/lib/core/util/logger.rb +147 -0
  41. data/lib/core/util/package.rb +93 -0
  42. data/lib/core/util/shell.rb +239 -0
  43. data/lib/nucleon/action/add.rb +69 -0
  44. data/lib/nucleon/action/create.rb +52 -0
  45. data/lib/nucleon/action/extract.rb +49 -0
  46. data/lib/nucleon/action/remove.rb +51 -0
  47. data/lib/nucleon/action/save.rb +53 -0
  48. data/lib/nucleon/action/update.rb +37 -0
  49. data/lib/nucleon/command/bash.rb +146 -0
  50. data/lib/nucleon/event/regex.rb +52 -0
  51. data/lib/nucleon/project/git.rb +465 -0
  52. data/lib/nucleon/project/github.rb +108 -0
  53. data/lib/nucleon/template/json.rb +16 -0
  54. data/lib/nucleon/template/wrapper.rb +16 -0
  55. data/lib/nucleon/template/yaml.rb +16 -0
  56. data/lib/nucleon/translator/json.rb +27 -0
  57. data/lib/nucleon/translator/yaml.rb +27 -0
  58. data/lib/nucleon.rb +18 -15
  59. data/locales/en.yml +3 -132
  60. data/nucleon.gemspec +66 -27
  61. data/spec/core/util/console_spec.rb +489 -0
  62. metadata +109 -96
@@ -0,0 +1,380 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::Macro::PluginInterface
5
+ #
6
+
7
+ nucleon_require(File.dirname(__FILE__), :object_interface)
8
+
9
+ #---
10
+
11
+ module Nucleon
12
+ module Mixin
13
+ module Macro
14
+ module PluginInterface
15
+
16
+ include Macro::ObjectInterface
17
+
18
+ #-----------------------------------------------------------------------------
19
+ # Plugin collections
20
+
21
+ def plugin_collection(_type, _method_options = {})
22
+ _method_config = Config.ensure(_method_options)
23
+ _method_config.set(:plugin, true)
24
+
25
+ _plural = _method_config.init(:plural, "#{_type}s").get(:plural)
26
+ _search_proc = _method_config.get(:search_proc)
27
+ _single_instance = _method_config.get(:single_instance, false)
28
+ _plugin_type = _method_config.get(:plugin_type, _type)
29
+
30
+ @@object_types[_type] = _method_config
31
+
32
+ logger.debug("Creating new plugin collection #{_type} with: #{_method_config.inspect}")
33
+
34
+ #---------------------------------------------------------------------------
35
+
36
+ object_utilities
37
+
38
+ #---
39
+
40
+ unless respond_to? :each_plugin
41
+ logger.debug("Defining plugin interface method: each_plugin")
42
+
43
+ define_method :each_plugin do |plugin_types = nil, providers = nil, &code|
44
+ providers = [ providers ] if providers && ! providers.is_a?(Array)
45
+
46
+ filter_proc = Proc.new {|type, config| config[:plugin] }
47
+ each_object_type(plugin_types, filter_proc) do |type, plural, options|
48
+ logger.debug("Processing plugin type #{type}/#{plural} with: #{options.inspect}")
49
+
50
+ send(plural).each do |provider, plugins|
51
+ logger.debug("Processing plugin provider: #{provider}")
52
+
53
+ unless providers && ! providers.include?(provider)
54
+ if plugins.is_a?(Hash)
55
+ plugins.each do |name, plugin|
56
+ logger.debug("Processing plugin: #{name}")
57
+ code.call(type, provider, name, plugin)
58
+ end
59
+ else
60
+ logger.debug("Processing plugin: #{plugin.name}")
61
+ code.call(type, provider, plugin.name, plugin)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ #---
70
+
71
+ logger.debug("Defining plugin interface method: each_#{_type}")
72
+
73
+ define_method "each_#{_type}" do |providers = nil, &code|
74
+ each_plugin(_type, providers) do |type, provider, name, plugin|
75
+ code.call(provider, name, plugin)
76
+ end
77
+ end
78
+
79
+ #---------------------------------------------------------------------------
80
+
81
+ logger.debug("Defining plugin interface method: #{_plural}")
82
+
83
+ define_method "#{_plural}" do |provider = nil, reset = false|
84
+ keys = ( provider ? [ _plural, provider ] : _plural )
85
+ send("init_#{_plural}", provider) if reset || _get(keys, {}).empty?
86
+ _get(keys, {})
87
+ end
88
+
89
+ #---
90
+
91
+ logger.debug("Defining plugin interface method: init_#{_plural}")
92
+
93
+ define_method "init_#{_plural}" do |providers = nil|
94
+ data = hash(_search_proc.call) if _search_proc
95
+ data = get_hash(_plural) unless data
96
+
97
+ providers = [ providers ] if providers && ! providers.is_a?(Array)
98
+
99
+ logger.debug("Initializing #{_plugin_type} plugin data: #{data.inspect}")
100
+ logger.debug("Providers: #{providers.inspect}")
101
+
102
+ symbol_map(data).each do |provider, instance_settings|
103
+ if ! providers || providers.include?(provider)
104
+ if _single_instance
105
+ logger.debug("Initializing single instance plugin: #{instance_settings.inspect}")
106
+
107
+ plugin = Nucleon.plugin(_plugin_type, provider, Config.ensure(instance_settings).import({ :meta => { :parent => myself } }))
108
+
109
+ _set([ _plural, provider ], plugin)
110
+ else
111
+ instance_settings.each do |name, options|
112
+ if name != :settings
113
+ logger.debug("Initializing plugin #{_plugin_type} #{name}: #{options.inspect}")
114
+
115
+ options[:name] = name
116
+ plugin = Nucleon.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
117
+
118
+ _set([ _plural, provider, name ], plugin)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ #---
127
+
128
+ logger.debug("Defining plugin interface method: set_#{_plural}")
129
+
130
+ define_method "set_#{_plural}" do |data = {}|
131
+ data = Config.ensure(data).export
132
+
133
+ send("clear_#{_plural}")
134
+ set(_plural, data)
135
+
136
+ logger.debug("Setting #{_plural}")
137
+
138
+ data.each do |provider, instance_settings|
139
+ if _single_instance
140
+ logger.debug("Setting single #{_plugin_type} #{provider}: #{instance_settings.inspect}")
141
+
142
+ plugin = Nucleon.plugin(_plugin_type, provider, Config.ensure(instance_settings).import({ :meta => { :parent => myself } }))
143
+
144
+ _set([ _plural, provider ], plugin)
145
+ else
146
+ instance_settings.each do |name, options|
147
+ logger.debug("Setting #{_plugin_type} #{provider} #{name}: #{options.inspect}")
148
+
149
+ options[:name] = name
150
+ plugin = Nucleon.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
151
+
152
+ _set([ _plural, provider, name ], plugin)
153
+ end
154
+ end
155
+ end
156
+ end
157
+
158
+ #---
159
+
160
+ logger.debug("Defining plugin interface method: clear_#{_plural}")
161
+
162
+ define_method "clear_#{_plural}" do
163
+ get(_plural).keys.each do |provider|
164
+ logger.debug("Clearing #{_type} #{provider}")
165
+
166
+ if _single_instance
167
+ send("delete_#{_type}", provider)
168
+ else
169
+ get_hash([ _plural, provider ]).keys.each do |name|
170
+ send("delete_#{_type}", provider, name)
171
+ end
172
+ end
173
+ end
174
+ end
175
+
176
+ #---------------------------------------------------------------------------
177
+
178
+ if _single_instance
179
+ logger.debug("Defining single instance plugin interface method: #{_type}_config")
180
+
181
+ define_method "#{_type}_config" do |provider = nil|
182
+ keys = [ _plural ]
183
+ keys << provider unless provider.nil?
184
+ Config.new(get(keys, {}))
185
+ end
186
+
187
+ #---
188
+
189
+ logger.debug("Defining single instance plugin interface method: #{_type}_setting")
190
+
191
+ define_method "#{_type}_setting" do |provider, property, default = nil, format = false|
192
+ get([ _plural, provider, property ], default, format)
193
+ end
194
+
195
+ #---
196
+
197
+ logger.debug("Defining single instance plugin interface method: #{_type}")
198
+
199
+ define_method "#{_type}" do |provider, reset = false|
200
+ if reset || _get([ _plural, provider ], nil).nil?
201
+ options = get([ _plural, provider ], nil)
202
+
203
+ unless options.nil?
204
+ plugin = Nucleon.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
205
+
206
+ logger.debug("Initializing plugin #{_plugin_type} #{provider}: #{options.inspect}")
207
+
208
+ _set([ _plural, provider ], plugin)
209
+ end
210
+ end
211
+ _get([ _plural, provider ])
212
+ end
213
+
214
+ #---
215
+
216
+ logger.debug("Defining single instance plugin interface method: set_#{_type}")
217
+
218
+ define_method "set_#{_type}" do |provider, options = {}|
219
+ options = Config.ensure(options).export
220
+
221
+ set([ _plural, provider ], options)
222
+
223
+ plugin = Nucleon.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
224
+
225
+ logger.debug("Setting single #{_plugin_type} #{provider}: #{options.inspect}")
226
+
227
+ _set([ _plural, provider ], plugin)
228
+ plugin
229
+ end
230
+
231
+ #---
232
+
233
+ logger.debug("Defining single instance plugin interface method: set_#{_type}_setting")
234
+
235
+ define_method "set_#{_type}_setting" do |provider, property, value = nil|
236
+ logger.debug("Setting single #{provider} property #{property} to #{value.inspect}")
237
+ set([ _plural, provider, property ], value)
238
+ end
239
+
240
+ #---
241
+
242
+ logger.debug("Defining single instance plugin interface method: delete_#{_type}")
243
+
244
+ define_method "delete_#{_type}" do |provider|
245
+ plugin = send(_type, provider)
246
+
247
+ logger.debug("Deleting single #{_type} #{provider}")
248
+
249
+ delete([ _plural, provider ])
250
+ _delete([ _plural, provider ])
251
+
252
+ Nucleon.remove_plugin(plugin) unless plugin.nil?
253
+ end
254
+
255
+ #---
256
+
257
+ logger.debug("Defining single instance plugin interface method: delete_#{_type}_setting")
258
+
259
+ define_method "delete_#{_type}_setting" do |provider, property|
260
+ logger.debug("Deleting single #{provider} property: #{property}")
261
+ delete([ _plural, provider, property ])
262
+ end
263
+
264
+ #---
265
+
266
+ logger.debug("Defining single instance plugin interface method: search_#{_type}")
267
+
268
+ define_method "search_#{_type}" do |provider, keys, default = '', format = false|
269
+ plugin_config = send("#{_type}_config", provider)
270
+ logger.debug("Searching single #{_type} #{provider}: #{plugin_config.inspect}")
271
+
272
+ search_object(plugin_config, keys, default, format)
273
+ end
274
+
275
+ #---------------------------------------------------------------------------
276
+ else
277
+ logger.debug("Defining multi instance plugin interface method: #{_type}_config")
278
+
279
+ define_method "#{_type}_config" do |provider = nil, name = nil|
280
+ keys = [ _plural ]
281
+ keys << provider unless provider.nil?
282
+ keys << name unless name.nil?
283
+ Config.new(get(keys, {}))
284
+ end
285
+
286
+ #---
287
+
288
+ logger.debug("Defining multi instance plugin interface method: #{_type}_setting")
289
+
290
+ define_method "#{_type}_setting" do |provider, name, property, default = nil, format = false|
291
+ get([ _plural, provider, name, property ], default, format)
292
+ end
293
+
294
+ #---
295
+
296
+ logger.debug("Defining multi instance plugin interface method: #{_type}")
297
+
298
+ define_method "#{_type}" do |provider, name|
299
+ if reset || _get([ _plural, provider, name ], nil).nil?
300
+ options = get([ _plural, provider, name ], nil)
301
+
302
+ unless options.nil?
303
+ options[:name] = name
304
+ plugin = Nucleon.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
305
+
306
+ logger.debug("Initializing plugin #{_plugin_type} #{provider}: #{options.inspect}")
307
+
308
+ _set([ _plural, provider, name ], plugin)
309
+ end
310
+ end
311
+ _get([ _plural, provider, name ])
312
+ end
313
+
314
+ #---
315
+
316
+ logger.debug("Defining multi instance plugin interface method: set_#{_type}")
317
+
318
+ define_method "set_#{_type}" do |provider, name, options = {}|
319
+ options = Config.ensure(options).export
320
+
321
+ set([ _plural, provider, name ], options)
322
+
323
+ options[:name] = name
324
+ plugin = Nucleon.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
325
+
326
+ logger.debug("Setting #{_plugin_type} #{provider} #{name}: #{options.inspect}")
327
+
328
+ _set([ _plural, provider, name ], plugin)
329
+ plugin
330
+ end
331
+
332
+ #---
333
+
334
+ logger.debug("Defining multi instance plugin interface method: set_#{_type}_setting")
335
+
336
+ define_method "set_#{_type}_setting" do |provider, name, property, value = nil|
337
+ logger.debug("Setting #{provider} #{name} property #{property} to #{value.inspect}")
338
+ set([ _plural, provider, name, property ], value)
339
+ end
340
+
341
+ #---
342
+
343
+ logger.debug("Defining multi instance plugin interface method: delete_#{_type}")
344
+
345
+ define_method "delete_#{_type}" do |provider, name|
346
+ plugin = send(_type, provider, name)
347
+
348
+ logger.debug("Deleting #{_type} #{provider} #{name}")
349
+
350
+ delete([ _plural, provider, name ])
351
+ _delete([ _plural, provider, name ])
352
+
353
+ Nucleon.remove_plugin(plugin) unless plugin.nil?
354
+ end
355
+
356
+ #---
357
+
358
+ logger.debug("Defining multi instance plugin interface method: delete_#{_type}_setting")
359
+
360
+ define_method "delete_#{_type}_setting" do |provider, name, property|
361
+ logger.debug("Deleting #{provider} #{name} property: #{property}")
362
+ delete([ _plural, provider, name, property ])
363
+ end
364
+
365
+ #---
366
+
367
+ logger.debug("Defining multi instance plugin interface method: search_#{_type}")
368
+
369
+ define_method "search_#{_type}" do |provider, name, keys, default = '', format = false|
370
+ plugin_config = send("#{_type}_config", provider, name)
371
+ logger.debug("Searching #{_type} #{provider} #{name}: #{plugin_config.inspect}")
372
+
373
+ search_object(plugin_config, keys, default, format)
374
+ end
375
+ end
376
+ end
377
+ end
378
+ end
379
+ end
380
+ end
@@ -0,0 +1,46 @@
1
+
2
+ # Should be included via include
3
+ #
4
+ # include Mixin::Settings
5
+ #
6
+
7
+ module Nucleon
8
+ module Mixin
9
+ module Settings
10
+
11
+ def settings(name)
12
+ return get_hash([ :settings, name ])
13
+ end
14
+
15
+ #---
16
+
17
+ def set_settings(name, settings = {})
18
+ return set([ :settings, name ], settings)
19
+ end
20
+
21
+ #---
22
+
23
+ def delete_settings(name)
24
+ return delete([ :settings, name ])
25
+ end
26
+
27
+ #---
28
+
29
+ def setting(name, key, default = '', format = false)
30
+ return get([ :settings, name, key ], default, format)
31
+ end
32
+
33
+ #---
34
+
35
+ def set_setting(name, key, value = '')
36
+ return set([ :settings, name, key ], value)
37
+ end
38
+
39
+ #---
40
+
41
+ def delete_setting(name, key)
42
+ return delete([ :settings, name, key ])
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,148 @@
1
+
2
+ # Should be included via include
3
+ #
4
+ # include Mixin::SubConfig
5
+ #
6
+
7
+ module Nucleon
8
+ module Mixin
9
+ module SubConfig
10
+
11
+ #-----------------------------------------------------------------------------
12
+ # Initialization
13
+
14
+ def init_subconfig(reset = false)
15
+ return if @subconfig_initialized && ! reset
16
+
17
+ unless @config
18
+ @config = Config.new
19
+ end
20
+
21
+ @subconfig_initialized = true
22
+ end
23
+ protected :init_subconfig
24
+
25
+ #-----------------------------------------------------------------------------
26
+ # Propety accessors / modifiers
27
+
28
+ def config
29
+ return @config
30
+ end
31
+
32
+ #---
33
+
34
+ def config=config
35
+ @config = config
36
+ end
37
+
38
+ #-----------------------------------------------------------------------------
39
+
40
+ def _get(keys, default = nil, format = false)
41
+ return fetch(@properties, array(keys).flatten, default, format)
42
+ end
43
+ protected :_get
44
+
45
+ #---
46
+
47
+ def get(keys, default = nil, format = false)
48
+ init_subconfig
49
+ return config.get(keys, default, format)
50
+ end
51
+
52
+ #---
53
+
54
+ def _init(keys, default = nil)
55
+ return _set(keys, _get(keys, default))
56
+ end
57
+ protected :_init
58
+
59
+ #---
60
+
61
+ def _set(keys, value = '')
62
+ modify(@properties, array(keys).flatten, value)
63
+ end
64
+ protected :_set
65
+
66
+ #---
67
+
68
+ def set(keys, value = '')
69
+ init_subconfig
70
+ config.set(keys, value)
71
+ end
72
+
73
+ #---
74
+
75
+ def _delete(keys, default = nil)
76
+ existing = modify(@properties, array(keys).flatten, nil)
77
+ return existing[:value] if existing[:value]
78
+ return default
79
+ end
80
+ protected :_delete
81
+
82
+ #---
83
+
84
+ def delete(keys, default = nil)
85
+ init_subconfig
86
+ config.delete(keys, default)
87
+ end
88
+
89
+ #---
90
+
91
+ def _clear
92
+ @properties = {}
93
+ end
94
+ protected :_clear
95
+
96
+ #---
97
+
98
+ def clear
99
+ init_subconfig
100
+ config.clear
101
+ end
102
+
103
+ #-----------------------------------------------------------------------------
104
+ # Import / Export
105
+
106
+ def _import(properties, options = {})
107
+ return import_base(properties, options)
108
+ end
109
+ protected :_import
110
+
111
+ #---
112
+
113
+ def import(properties, options = {})
114
+ init_subconfig
115
+ config.import(properties, options)
116
+ end
117
+
118
+ #---
119
+
120
+ def _defaults(defaults, options = {})
121
+ config = new(options).set(:import_type, :default)
122
+ return import_base(defaults, config)
123
+ end
124
+ protected :_defaults
125
+
126
+ #---
127
+
128
+ def defaults(defaults, options = {})
129
+ init_subconfig
130
+ config.defaults(defaults, options)
131
+ end
132
+
133
+ #---
134
+
135
+ def _export
136
+ return @properties
137
+ end
138
+ protected :_export
139
+
140
+ #---
141
+
142
+ def export
143
+ init_subconfig
144
+ return config.export
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,29 @@
1
+
2
+ #-------------------------------------------------------------------------------
3
+ # Hash data type alterations
4
+
5
+ class Hash
6
+ def search(search_key, options = {})
7
+ config = Nucleon::Config.ensure(options)
8
+ value = nil
9
+
10
+ recurse = config.get(:recurse, false)
11
+ recurse_level = config.get(:recurse_level, -1)
12
+
13
+ self.each do |key, data|
14
+ if key == search_key
15
+ value = data
16
+
17
+ elsif data.is_a?(Hash) &&
18
+ recurse && (recurse_level == -1 || recurse_level > 0)
19
+
20
+ recurse_level -= 1 unless recurse_level == -1
21
+ value = value.search(search_key,
22
+ Nucleon::Config.new(config).set(:recurse_level, recurse_level)
23
+ )
24
+ end
25
+ break unless value.nil?
26
+ end
27
+ return value
28
+ end
29
+ end