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,52 @@
1
+
2
+ module Nucleon
3
+ module Mixin
4
+ module Action
5
+ module Push
6
+
7
+ #-----------------------------------------------------------------------------
8
+ # Options
9
+
10
+ def push_options(parser, optional = true)
11
+ if optional
12
+ parser.option_bool(:push, false,
13
+ '--push',
14
+ 'nucleon.core.mixins.push.options.push'
15
+ )
16
+ else
17
+ parser.options[:push] = true
18
+ end
19
+
20
+ parser.option_bool(:propogate, false,
21
+ '--propogate',
22
+ 'nucleon.core.mixins.push.options.propogate'
23
+ )
24
+ parser.option_str(:remote, :edit,
25
+ '--remote PROJECT_REMOTE',
26
+ 'nucleon.core.mixins.push.options.remote'
27
+ )
28
+ parser.option_str(:revision, :master,
29
+ '--revision PROJECT_REVISION',
30
+ 'nucleon.core.mixins.push.options.revision'
31
+ )
32
+ end
33
+
34
+ #-----------------------------------------------------------------------------
35
+ # Operations
36
+
37
+ def push(project, remote = :edit)
38
+ success = true
39
+
40
+ if project && settings[:push]
41
+ success = project.push(settings[:remote], extended_config(:push, {
42
+ :revision => settings[:revision],
43
+ :propogate => settings[:propogate]
44
+ }))
45
+ end
46
+ success
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,53 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::ConfigCollection
5
+ #
6
+
7
+ module Nucleon
8
+ module Mixin
9
+ module ConfigCollection
10
+
11
+ #-----------------------------------------------------------------------------
12
+ # Configuration collection interface
13
+
14
+ def all_properties
15
+ return Config::Collection.all
16
+ end
17
+
18
+ #---
19
+
20
+ def get_property(name)
21
+ return Config::Collection.get(name)
22
+ end
23
+
24
+ #---
25
+
26
+ def set_property(name, value)
27
+ Config::Collection.set(name, value)
28
+ return self
29
+ end
30
+
31
+ #---
32
+
33
+ def delete_property(name)
34
+ Config::Collection.delete(name)
35
+ return self
36
+ end
37
+
38
+ #---
39
+
40
+ def clear_properties
41
+ Config::Collection.clear
42
+ return self
43
+ end
44
+
45
+ #---
46
+
47
+ def save_properties
48
+ Config::Collection.save
49
+ return self
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,39 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::ConfigOptions
5
+ #
6
+
7
+ module Nucleon
8
+ module Mixin
9
+ module ConfigOptions
10
+
11
+ #-----------------------------------------------------------------------------
12
+ # Configuration options interface
13
+
14
+ def contexts(contexts = [], hierarchy = [])
15
+ return Config::Options.contexts(contexts, hierarchy)
16
+ end
17
+
18
+ #---
19
+
20
+ def get_options(contexts, force = true)
21
+ return Config::Options.get(contexts, force)
22
+ end
23
+
24
+ #---
25
+
26
+ def set_options(contexts, options, force = true)
27
+ Config::Options.set(contexts, options, force)
28
+ return self
29
+ end
30
+
31
+ #---
32
+
33
+ def clear_options(contexts)
34
+ Config::Options.clear(contexts)
35
+ return self
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,361 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::Macro::ObjectInterface
5
+ #
6
+
7
+ module Nucleon
8
+ module Mixin
9
+ module Macro
10
+ module ObjectInterface
11
+
12
+ # requires Mixin::SubConfig
13
+ # requires Mixin::Settings
14
+
15
+ #-----------------------------------------------------------------------------
16
+ # Object collections
17
+
18
+ @@object_types = {}
19
+
20
+ #---
21
+
22
+ def object_collection(_type, _method_options = {})
23
+ _method_config = Config.ensure(_method_options)
24
+
25
+ _plural = _method_config.init(:plural, "#{_type}s").get(:plural)
26
+
27
+ unless _ensure_proc = _method_config.get(:ensure_proc, false)
28
+ _ensure_proc = Proc.new {|name, options = {}| options }
29
+ end
30
+ _delete_proc = _method_config.get(:delete_proc)
31
+ _search_proc = _method_config.get(:search_proc)
32
+
33
+ @@object_types[_type] = _method_config
34
+
35
+ logger.debug("Creating new object collection #{_type} with: #{_method_config.inspect}")
36
+
37
+ #---------------------------------------------------------------------------
38
+
39
+ object_utilities
40
+
41
+ #---------------------------------------------------------------------------
42
+
43
+ logger.debug("Defining object interface method: #{_type}_config")
44
+
45
+ define_method "#{_type}_config" do |name = nil|
46
+ Config.new( name ? get([ _plural, name ], {}) : get(_plural, {}) )
47
+ end
48
+
49
+ #---
50
+
51
+ logger.debug("Defining object interface method: #{_type}_setting")
52
+
53
+ define_method "#{_type}_setting" do |name, property, default = nil, format = false|
54
+ get([ _plural, name, property ], default, format)
55
+ end
56
+
57
+ #---
58
+
59
+ logger.debug("Defining object interface method: #{_plural}")
60
+
61
+ define_method "#{_plural}" do |reset = false|
62
+ send("init_#{_plural}") if reset || _get(_plural, {}).empty?
63
+ _get(_plural, {})
64
+ end
65
+
66
+ #---
67
+
68
+ logger.debug("Defining object interface method: init_#{_plural}")
69
+
70
+ define_method "init_#{_plural}" do
71
+ data = hash(_search_proc.call) if _search_proc
72
+ data = get_hash(_plural) unless data
73
+
74
+ logger.debug("Initializing object data: #{data.inspect}")
75
+
76
+ symbol_map(data).each do |name, options|
77
+ if name != :settings
78
+ options[:object_container] = myself
79
+
80
+ logger.debug("Initializing object: #{name}")
81
+
82
+ obj = _ensure_proc.call(name, options)
83
+ _set([ _plural, name ], obj)
84
+ end
85
+ end
86
+ end
87
+
88
+ #---
89
+
90
+ logger.debug("Defining object interface method: set_#{_plural}")
91
+
92
+ define_method "set_#{_plural}" do |data = {}|
93
+ data = Config.ensure(data).export
94
+
95
+ send("clear_#{_plural}")
96
+ set(_plural, data)
97
+
98
+ logger.debug("Setting #{_plural}")
99
+
100
+ data.each do |name, options|
101
+ options[:object_container] = myself
102
+
103
+ logger.debug("Setting #{_type} #{name}: #{options.inspect}")
104
+
105
+ obj = _ensure_proc.call(name, options)
106
+ _set([ _plural, name ], obj)
107
+ end
108
+ end
109
+
110
+ #---
111
+
112
+ logger.debug("Defining object interface method: #{_type}")
113
+
114
+ define_method "#{_type}" do |name, reset = false|
115
+ if reset || _get([ _plural, name ], nil).nil?
116
+ options = get([ _plural, name ], nil)
117
+
118
+ unless options.nil?
119
+ options[:object_container] = myself
120
+
121
+ logger.debug("Initializing object: #{name}")
122
+
123
+ obj = _ensure_proc.call(name, options)
124
+ _set([ _plural, name ], obj)
125
+ end
126
+ end
127
+ _get([ _plural, name ])
128
+ end
129
+
130
+ #---
131
+
132
+ logger.debug("Defining object interface method: set_#{_type}")
133
+
134
+ define_method "set_#{_type}" do |name, options = {}|
135
+ options = Config.ensure(options).export
136
+
137
+ set([ _plural, name ], options)
138
+
139
+ options[:object_container] = myself
140
+
141
+ logger.debug("Setting #{_type} #{_name}: #{options.inspect}")
142
+
143
+ obj = _ensure_proc.call(name, options)
144
+ _set([ _plural, name ], obj)
145
+ end
146
+
147
+ #---
148
+
149
+ logger.debug("Defining object interface method: set_#{_type}_setting")
150
+
151
+ define_method "set_#{_type}_setting" do |name, property, value = nil|
152
+ logger.debug("Setting #{name} property #{property} to #{value.inspect}")
153
+ set([ _plural, name, property ], value)
154
+ end
155
+
156
+ #---
157
+
158
+ logger.debug("Defining object interface method: delete_#{_type}")
159
+
160
+ define_method "delete_#{_type}" do |name|
161
+ obj = send(_type, name)
162
+
163
+ logger.debug("Deleting #{_type} #{name}")
164
+
165
+ delete([ _plural, name ])
166
+ _delete([ _plural, name ])
167
+
168
+ _delete_proc.call(obj) if _delete_proc && ! obj.nil?
169
+ end
170
+
171
+ #---
172
+
173
+ logger.debug("Defining object interface method: delete_#{_type}_setting")
174
+
175
+ define_method "delete_#{_type}_setting" do |name, property|
176
+ logger.debug("Deleting #{name} property: #{property}")
177
+
178
+ delete([ _plural, name, property ])
179
+ end
180
+
181
+ #---
182
+
183
+ logger.debug("Defining object interface method: clear_#{_plural}")
184
+
185
+ define_method "clear_#{_plural}" do
186
+ get(_plural).keys.each do |name|
187
+ logger.debug("Clearing #{_type} #{name}")
188
+
189
+ send("delete_#{_type}", name)
190
+ end
191
+ end
192
+
193
+ #---------------------------------------------------------------------------
194
+
195
+ logger.debug("Defining object interface method: search_#{_type}")
196
+
197
+ define_method "search_#{_type}" do |name, keys, default = '', format = false|
198
+ obj_config = send("#{_type}_config", name)
199
+ search_object(obj_config, keys, default, format)
200
+ end
201
+ end
202
+
203
+ #-----------------------------------------------------------------------------
204
+ # Utilities
205
+
206
+ def object_utilities
207
+
208
+ unless respond_to? :each_object_type
209
+ logger.debug("Defining object utility method: each_object_type")
210
+
211
+ define_method :each_object_type do |object_types = nil, filter_proc = nil, &code|
212
+ object_types = @@object_types.keys unless object_types
213
+ object_types = [ object_types ] unless object_types.is_a?(Array)
214
+
215
+ object_types.each do |type|
216
+ logger.debug("Processing object type: #{type}")
217
+
218
+ unless filter_proc && ! filter_proc.call(type, @@object_types[type])
219
+ plural = @@object_types[type][:plural]
220
+
221
+ logger.debug("Passing: #{@@object_types[type].inspect}")
222
+ code.call(type, plural, @@object_types[type])
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ #---
229
+
230
+ unless respond_to? :each_object
231
+ logger.debug("Defining object utility method: each_object")
232
+
233
+ define_method :each_object do |object_types = nil, &code|
234
+ each_object_type(object_types) do |type, plural, options|
235
+ logger.debug("Processing object type #{type}/#{plural} with: #{options.inspect}")
236
+
237
+ send(plural).each do |name, obj|
238
+ logger.debug("Processing object: #{name}")
239
+ code.call(type, name, obj)
240
+ end
241
+ end
242
+ end
243
+ end
244
+
245
+ #---
246
+
247
+ unless respond_to? :init_objects
248
+ logger.debug("Defining object utility method: init_objects")
249
+
250
+ define_method :init_objects do |object_types = nil, filter_proc = nil|
251
+ logger.debug("Initializing object collection")
252
+
253
+ each_object_type(object_types, filter_proc) do |type, plural, options|
254
+ send("init_#{plural}")
255
+ end
256
+ end
257
+ end
258
+
259
+ #---
260
+
261
+ unless respond_to? :clear_objects
262
+ logger.debug("Defining object utility method: clear_objects")
263
+
264
+ define_method :clear_objects do |object_types = nil, filter_proc = nil|
265
+ logger.debug("Clearing object collection")
266
+
267
+ each_object_type(object_types, filter_proc) do |type, plural, options|
268
+ send("clear_#{plural}")
269
+ end
270
+ end
271
+ end
272
+
273
+ #---------------------------------------------------------------------------
274
+
275
+ unless respond_to? :search_object
276
+ logger.debug("Defining object utility method: search_object")
277
+
278
+ define_method :search_object do |obj_config, keys, default = '', format = false|
279
+ obj_config = Marshal.load(Marshal.dump(obj_config))
280
+ value = obj_config.get(keys)
281
+
282
+ logger.debug("Searching object properties: #{obj_config.inspect}")
283
+
284
+ if ! value || value.is_a?(Hash)
285
+ settings = {}
286
+
287
+ keys = [ keys ] unless keys.is_a?(Array)
288
+ temp = keys.dup
289
+
290
+ logger.debug("Searching object keys: #{keys.inspect}")
291
+
292
+ logger.debug("Searching specialized settings")
293
+ until temp.empty? do
294
+ if obj_settings = obj_config.delete([ temp, :settings ])
295
+ array(obj_settings).each do |group_name|
296
+ if group_settings = Marshal.load(Marshal.dump(settings(group_name)))
297
+ settings = Util::Data.merge([ group_settings.dup, settings ], true)
298
+ end
299
+ end
300
+ end
301
+ temp.pop
302
+ end
303
+
304
+ logger.debug("Specialized settings found: #{settings.inspect}")
305
+ logger.debug("Searching general settings")
306
+
307
+ if obj_settings = obj_config.delete(:settings)
308
+ array(obj_settings).each do |group_name|
309
+ if group_settings = Marshal.load(Marshal.dump(settings(group_name)))
310
+ settings = Util::Data.merge([ group_settings, settings ], true)
311
+ end
312
+ end
313
+ end
314
+
315
+ logger.debug("Final settings found: #{settings.inspect}")
316
+
317
+ unless settings.empty?
318
+ final_config = Config.new(Util::Data.merge([ settings, obj_config.export ], true))
319
+ value = final_config.get(keys)
320
+
321
+ logger.debug("Final configuration: #{final_config.export.inspect}")
322
+ end
323
+
324
+ value = default if Util::Data.undef?(value)
325
+ end
326
+
327
+ logger.debug("Final value found (format: #{format.inspect}): #{value.inspect}")
328
+ filter(value, format)
329
+ end
330
+ end
331
+
332
+ #---------------------------------------------------------------------------
333
+ # Configuration loading saving
334
+
335
+ unless respond_to? :load
336
+ logger.debug("Defining object utility method: load")
337
+
338
+ define_method :load do |options = {}|
339
+ logger.debug("Loading configuration if possible")
340
+ if config.respond_to?(:load)
341
+ clear_objects
342
+ config.load(options)
343
+ end
344
+ end
345
+ end
346
+
347
+ #---
348
+
349
+ unless respond_to? :save
350
+ logger.debug("Defining object utility method: save")
351
+
352
+ define_method :save do |options = {}|
353
+ logger.debug("Saving configuration if possible")
354
+ config.save(options) if config.respond_to?(:save)
355
+ end
356
+ end
357
+ end
358
+ end
359
+ end
360
+ end
361
+ end