corl 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/.document +5 -0
  2. data/.gitmodules +4 -0
  3. data/Gemfile +24 -0
  4. data/Gemfile.lock +123 -0
  5. data/LICENSE.txt +674 -0
  6. data/README.rdoc +27 -0
  7. data/Rakefile +78 -0
  8. data/VERSION +1 -0
  9. data/bin/corl +55 -0
  10. data/corl.gemspec +228 -0
  11. data/lib/corl/action/add.rb +69 -0
  12. data/lib/corl/action/bootstrap.rb +83 -0
  13. data/lib/corl/action/clone.rb +40 -0
  14. data/lib/corl/action/create.rb +55 -0
  15. data/lib/corl/action/exec.rb +41 -0
  16. data/lib/corl/action/extract.rb +49 -0
  17. data/lib/corl/action/image.rb +30 -0
  18. data/lib/corl/action/images.rb +55 -0
  19. data/lib/corl/action/lookup.rb +35 -0
  20. data/lib/corl/action/machines.rb +51 -0
  21. data/lib/corl/action/provision.rb +37 -0
  22. data/lib/corl/action/remove.rb +51 -0
  23. data/lib/corl/action/save.rb +53 -0
  24. data/lib/corl/action/seed.rb +115 -0
  25. data/lib/corl/action/spawn.rb +75 -0
  26. data/lib/corl/action/start.rb +37 -0
  27. data/lib/corl/action/stop.rb +30 -0
  28. data/lib/corl/action/update.rb +37 -0
  29. data/lib/corl/command/shell.rb +164 -0
  30. data/lib/corl/configuration/file.rb +386 -0
  31. data/lib/corl/event/puppet.rb +90 -0
  32. data/lib/corl/event/regex.rb +52 -0
  33. data/lib/corl/extension/puppetloader.rb +24 -0
  34. data/lib/corl/machine/fog.rb +310 -0
  35. data/lib/corl/machine/physical.rb +161 -0
  36. data/lib/corl/network/default.rb +26 -0
  37. data/lib/corl/node/aws.rb +90 -0
  38. data/lib/corl/node/fog.rb +198 -0
  39. data/lib/corl/node/google.rb +115 -0
  40. data/lib/corl/node/local.rb +26 -0
  41. data/lib/corl/node/rackspace.rb +89 -0
  42. data/lib/corl/project/git.rb +465 -0
  43. data/lib/corl/project/github.rb +108 -0
  44. data/lib/corl/provisioner/puppetnode/resource.rb +245 -0
  45. data/lib/corl/provisioner/puppetnode/resource_group.rb +205 -0
  46. data/lib/corl/provisioner/puppetnode.rb +407 -0
  47. data/lib/corl/template/environment.rb +73 -0
  48. data/lib/corl/template/json.rb +16 -0
  49. data/lib/corl/template/wrapper.rb +16 -0
  50. data/lib/corl/template/yaml.rb +16 -0
  51. data/lib/corl/translator/json.rb +27 -0
  52. data/lib/corl/translator/yaml.rb +27 -0
  53. data/lib/corl.rb +173 -0
  54. data/lib/corl_core/codes.rb +107 -0
  55. data/lib/corl_core/config/collection.rb +57 -0
  56. data/lib/corl_core/config/options.rb +70 -0
  57. data/lib/corl_core/config.rb +337 -0
  58. data/lib/corl_core/core.rb +59 -0
  59. data/lib/corl_core/corl.rb +254 -0
  60. data/lib/corl_core/errors.rb +84 -0
  61. data/lib/corl_core/facade.rb +126 -0
  62. data/lib/corl_core/gems.rb +72 -0
  63. data/lib/corl_core/manager.rb +425 -0
  64. data/lib/corl_core/mixin/action/commit.rb +58 -0
  65. data/lib/corl_core/mixin/action/keypair.rb +105 -0
  66. data/lib/corl_core/mixin/action/node.rb +129 -0
  67. data/lib/corl_core/mixin/action/project.rb +53 -0
  68. data/lib/corl_core/mixin/action/push.rb +52 -0
  69. data/lib/corl_core/mixin/config/collection.rb +53 -0
  70. data/lib/corl_core/mixin/config/ops.rb +53 -0
  71. data/lib/corl_core/mixin/config/options.rb +39 -0
  72. data/lib/corl_core/mixin/lookup.rb +196 -0
  73. data/lib/corl_core/mixin/macro/object_interface.rb +361 -0
  74. data/lib/corl_core/mixin/macro/plugin_interface.rb +380 -0
  75. data/lib/corl_core/mixin/settings.rb +46 -0
  76. data/lib/corl_core/mixin/sub_config.rb +148 -0
  77. data/lib/corl_core/mod/hash.rb +29 -0
  78. data/lib/corl_core/mod/hiera_backend.rb +63 -0
  79. data/lib/corl_core/plugin/action.rb +381 -0
  80. data/lib/corl_core/plugin/base.rb +374 -0
  81. data/lib/corl_core/plugin/command.rb +98 -0
  82. data/lib/corl_core/plugin/configuration.rb +177 -0
  83. data/lib/corl_core/plugin/event.rb +53 -0
  84. data/lib/corl_core/plugin/extension.rb +12 -0
  85. data/lib/corl_core/plugin/machine.rb +266 -0
  86. data/lib/corl_core/plugin/network.rb +359 -0
  87. data/lib/corl_core/plugin/node.rb +904 -0
  88. data/lib/corl_core/plugin/project.rb +927 -0
  89. data/lib/corl_core/plugin/provisioner.rb +51 -0
  90. data/lib/corl_core/plugin/template.rb +80 -0
  91. data/lib/corl_core/plugin/translator.rb +38 -0
  92. data/lib/corl_core/util/cli.rb +352 -0
  93. data/lib/corl_core/util/data.rb +404 -0
  94. data/lib/corl_core/util/disk.rb +114 -0
  95. data/lib/corl_core/util/git.rb +47 -0
  96. data/lib/corl_core/util/interface.rb +319 -0
  97. data/lib/corl_core/util/liquid.rb +17 -0
  98. data/lib/corl_core/util/package.rb +93 -0
  99. data/lib/corl_core/util/shell.rb +239 -0
  100. data/lib/corl_core/util/ssh.rb +286 -0
  101. data/lib/facter/corl_config_ready.rb +13 -0
  102. data/lib/facter/corl_exists.rb +15 -0
  103. data/lib/facter/corl_network.rb +17 -0
  104. data/lib/hiera/corl_logger.rb +18 -0
  105. data/lib/puppet/indirector/corl.rb +27 -0
  106. data/lib/puppet/indirector/data_binding/corl.rb +6 -0
  107. data/lib/puppet/parser/functions/config_initialized.rb +26 -0
  108. data/lib/puppet/parser/functions/corl_include.rb +44 -0
  109. data/lib/puppet/parser/functions/corl_resources.rb +58 -0
  110. data/lib/puppet/parser/functions/deep_merge.rb +21 -0
  111. data/lib/puppet/parser/functions/ensure.rb +29 -0
  112. data/lib/puppet/parser/functions/file_exists.rb +19 -0
  113. data/lib/puppet/parser/functions/global_array.rb +35 -0
  114. data/lib/puppet/parser/functions/global_hash.rb +35 -0
  115. data/lib/puppet/parser/functions/global_options.rb +23 -0
  116. data/lib/puppet/parser/functions/global_param.rb +43 -0
  117. data/lib/puppet/parser/functions/interpolate.rb +26 -0
  118. data/lib/puppet/parser/functions/is_false.rb +21 -0
  119. data/lib/puppet/parser/functions/is_true.rb +21 -0
  120. data/lib/puppet/parser/functions/module_array.rb +38 -0
  121. data/lib/puppet/parser/functions/module_hash.rb +38 -0
  122. data/lib/puppet/parser/functions/module_options.rb +23 -0
  123. data/lib/puppet/parser/functions/module_param.rb +48 -0
  124. data/lib/puppet/parser/functions/name.rb +21 -0
  125. data/lib/puppet/parser/functions/render.rb +33 -0
  126. data/lib/puppet/parser/functions/value.rb +21 -0
  127. data/locales/en.yml +232 -0
  128. data/spec/corl_core/interface_spec.rb +489 -0
  129. data/spec/corl_mock_input.rb +29 -0
  130. data/spec/corl_test_kernel.rb +22 -0
  131. data/spec/spec_helper.rb +15 -0
  132. metadata +406 -0
@@ -0,0 +1,126 @@
1
+
2
+ module CORL
3
+
4
+ #-----------------------------------------------------------------------------
5
+ # Core plugin type facade
6
+
7
+ def self.extension(provider)
8
+ plugin(:extension, provider, {})
9
+ end
10
+
11
+ #---
12
+
13
+ def self.configuration(options, provider = nil)
14
+ plugin(:configuration, provider, options)
15
+ end
16
+
17
+ def self.configurations(data, build_hash = false, keep_array = false)
18
+ plugins(:configuration, data, build_hash, keep_array)
19
+ end
20
+
21
+ #---
22
+
23
+ def self.action(provider, options)
24
+ plugin(:action, provider, options)
25
+ end
26
+
27
+ def self.action_config(provider)
28
+ action(provider, { :settings => {}, :quiet => true }).configure
29
+ end
30
+
31
+ def self.actions(data, build_hash = false, keep_array = false)
32
+ plugins(:action, data, build_hash, keep_array)
33
+ end
34
+
35
+ def self.action_run(provider, options = {}, quiet = true)
36
+ Plugin::Action.exec(provider, options, quiet)
37
+ end
38
+
39
+ def self.action_cli(provider, args = [], quiet = false)
40
+ Plugin::Action.exec_cli(provider, args, quiet)
41
+ end
42
+
43
+ #---
44
+
45
+ def self.project(options, provider = nil)
46
+ plugin(:project, provider, options)
47
+ end
48
+
49
+ def self.projects(data, build_hash = false, keep_array = false)
50
+ plugins(:project, data, build_hash, keep_array)
51
+ end
52
+
53
+ #-----------------------------------------------------------------------------
54
+ # Cluster plugin type facade
55
+
56
+ def self.network(name, options = {}, provider = nil)
57
+ plugin(:network, provider, Config.ensure(options).import({ :name => name }))
58
+ end
59
+
60
+ def self.networks(data, build_hash = false, keep_array = false)
61
+ plugins(:network, data, build_hash, keep_array)
62
+ end
63
+
64
+ #---
65
+
66
+ def self.node(name, options = {}, provider = nil)
67
+ plugin(:node, provider, Config.ensure(options).import({ :name => name }))
68
+ end
69
+
70
+ def self.nodes(data, build_hash = false, keep_array = false)
71
+ plugins(:node, data, build_hash, keep_array)
72
+ end
73
+
74
+ #---
75
+
76
+ def self.provisioner(options, provider = nil)
77
+ plugin(:provisioner, provider, options)
78
+ end
79
+
80
+ #---
81
+
82
+ def self.provisioners(data, build_hash = false, keep_array = false)
83
+ plugins(:provisioner, data, build_hash, keep_array)
84
+ end
85
+
86
+ #---
87
+
88
+ def self.command(options, provider = nil)
89
+ plugin(:command, provider, options)
90
+ end
91
+
92
+ def self.commands(data, build_hash = false, keep_array = false)
93
+ plugins(:command, data, build_hash, keep_array)
94
+ end
95
+
96
+ #-----------------------------------------------------------------------------
97
+ # Utility plugin type facade
98
+
99
+ def self.event(options, provider = nil)
100
+ plugin(:event, provider, options)
101
+ end
102
+
103
+ def self.events(data, build_hash = false, keep_array = false)
104
+ plugins(:event, data, build_hash, keep_array)
105
+ end
106
+
107
+ #---
108
+
109
+ def self.template(options, provider = nil)
110
+ plugin(:template, provider, options)
111
+ end
112
+
113
+ def self.templates(data, build_hash = false, keep_array = false)
114
+ plugins(:template, data, build_hash, keep_array)
115
+ end
116
+
117
+ #---
118
+
119
+ def self.translator(options, provider = nil)
120
+ plugin(:translator, provider, options)
121
+ end
122
+
123
+ def self.translators(data, build_hash = false, keep_array = false)
124
+ plugins(:translator, data, build_hash, keep_array)
125
+ end
126
+ end
@@ -0,0 +1,72 @@
1
+
2
+ module CORL
3
+ module Gems
4
+
5
+ #-----------------------------------------------------------------------------
6
+
7
+ @@core = nil
8
+ @@gems = {}
9
+
10
+ #-----------------------------------------------------------------------------
11
+ # Gem interface
12
+
13
+ def self.logger
14
+ Core.logger
15
+ end
16
+
17
+ #---
18
+
19
+ def self.core
20
+ @@core
21
+ end
22
+
23
+ #---
24
+
25
+ def self.registered
26
+ @@gems
27
+ end
28
+
29
+ #---
30
+
31
+ def self.register(reset = false)
32
+ if reset || Util::Data.empty?(@@gems)
33
+ logger.info("Registering external gem defined CORL plugins at #{Time.now}")
34
+
35
+ if defined?(Gem)
36
+ if ! defined?(Bundler) && Gem::Specification.respond_to?(:latest_specs)
37
+ logger.debug("Not using bundler")
38
+ Gem::Specification.latest_specs(true).each do |spec|
39
+ register_gem(spec)
40
+ end
41
+ else
42
+ logger.debug("Using bundler or Gem specification without latest_specs")
43
+ Gem.loaded_specs.each do |name, spec|
44
+ register_gem(spec)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ @@gems
50
+ end
51
+
52
+ #---
53
+
54
+ def self.register_gem(spec)
55
+ plugin_path = File.join(spec.full_gem_path, 'lib', 'corl')
56
+ if File.directory?(plugin_path)
57
+ logger.info("Registering gem #{spec.name} at #{plugin_path} at #{Time.now}")
58
+
59
+ @@gems[spec.name] = {
60
+ :lib_dir => plugin_path,
61
+ :spec => spec
62
+ }
63
+ if spec.name == 'corl_core'
64
+ logger.debug("Setting CORL core gemspec")
65
+ @@core = spec
66
+ else
67
+ Manager.connection.register(plugin_path) # Autoload plugins and related files
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,425 @@
1
+
2
+ module CORL
3
+ class Manager
4
+
5
+ include Celluloid
6
+
7
+ #-----------------------------------------------------------------------------
8
+
9
+ @@supervisors = {}
10
+
11
+ #-----------------------------------------------------------------------------
12
+ # Plugin manager interface
13
+
14
+ def self.init_manager(name)
15
+ name = name.to_sym
16
+
17
+ Manager.supervise_as name
18
+ @@supervisors[name] = Celluloid::Actor[name]
19
+ end
20
+
21
+ #---
22
+
23
+ def self.connection(name = :core)
24
+ name = name.to_sym
25
+
26
+ init_manager(name) unless @@supervisors.has_key?(name)
27
+
28
+ begin
29
+ @@supervisors[name].test_connection
30
+ rescue Celluloid::DeadActorError
31
+ retry
32
+ end
33
+ @@supervisors[name]
34
+ end
35
+
36
+ #---
37
+
38
+ def initialize
39
+ @logger = CORL.logger
40
+
41
+ @types = {}
42
+ @load_info = {}
43
+ @plugins = {}
44
+ end
45
+
46
+ #-----------------------------------------------------------------------------
47
+ # Property accessor / modifiers
48
+
49
+ attr_reader :logger
50
+
51
+ #---
52
+
53
+ def types
54
+ @types.keys
55
+ end
56
+
57
+ #---
58
+
59
+ def type_default(type)
60
+ @types[type.to_sym]
61
+ end
62
+
63
+ #---
64
+
65
+ def loaded_plugins(type = nil, provider = nil)
66
+ results = {}
67
+ type = type.to_sym if type
68
+ provider = provider.to_sym if provider
69
+
70
+ if type && @load_info.has_key?(type)
71
+ if provider && @load_info.has_key?(provider)
72
+ results = @load_info[type][provider]
73
+ else
74
+ results = @load_info[type]
75
+ end
76
+ elsif ! type
77
+ results = @load_info
78
+ end
79
+ results
80
+ end
81
+
82
+ #---
83
+
84
+ def plugins(type = nil, provider = nil)
85
+ results = {}
86
+ type = type.to_sym if type
87
+ provider = provider.to_sym if provider
88
+
89
+ if type && @plugins.has_key?(type)
90
+ if provider && ! @plugins[type].keys.empty?
91
+ @plugins[type].each do |instance_name, plugin|
92
+ plugin = @plugins[type][instance_name]
93
+ results[instance_name] = plugin if plugin.plugin_provider == provider
94
+ end
95
+ else
96
+ results = @plugins[type]
97
+ end
98
+ elsif ! type
99
+ results = @plugins
100
+ end
101
+ results
102
+ end
103
+
104
+ #-----------------------------------------------------------------------------
105
+ # Operations
106
+
107
+ def test_connection
108
+ true
109
+ end
110
+
111
+ #---
112
+
113
+ def define_type(type_info)
114
+ if type_info.is_a?(Hash)
115
+ logger.info("Defining plugin types at #{Time.now}")
116
+
117
+ type_info.each do |type, default_provider|
118
+ logger.debug("Mapping plugin type #{type} to default provider #{default_provider}")
119
+ @types[type.to_sym] = default_provider
120
+ end
121
+ else
122
+ logger.warn("Defined types must be specified as a hash to be registered properly")
123
+ end
124
+ end
125
+
126
+ #---
127
+
128
+ def load_plugins(reset_gems = false)
129
+ # Register core plugins
130
+ unless @core_loaded
131
+ logger.info("Initializing core plugins at #{Time.now}")
132
+ register(File.join(File.dirname(__FILE__), '..', 'corl'))
133
+ @core_loaded = true
134
+ end
135
+
136
+ # Register external Gem defined plugins
137
+ Gems.register(reset_gems)
138
+
139
+ # Register any other extension plugins
140
+ exec(:register_plugins)
141
+
142
+ # Autoload all registered plugins
143
+ autoload
144
+ end
145
+
146
+ #---
147
+
148
+ def register(base_path)
149
+ if File.directory?(base_path)
150
+ logger.info("Loading files from #{base_path} at #{Time.now}")
151
+
152
+ Dir.glob(File.join(base_path, '*.rb')).each do |file|
153
+ logger.debug("Loading file: #{file}")
154
+ require file
155
+ end
156
+
157
+ logger.info("Loading directories from #{base_path} at #{Time.now}")
158
+ Dir.entries(base_path).each do |path|
159
+ unless path.match(/^\.\.?$/)
160
+ register_type(base_path, path)
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ #---
167
+
168
+ def register_type(base_path, plugin_type)
169
+ base_directory = File.join(base_path, plugin_type.to_s)
170
+
171
+ if File.directory?(base_directory)
172
+ logger.info("Registering #{base_directory} at #{Time.now}")
173
+
174
+ Dir.glob(File.join(base_directory, '*.rb')).each do |file|
175
+ add_build_info(plugin_type, file)
176
+ end
177
+ end
178
+ end
179
+ protected :register_type
180
+
181
+ #---
182
+
183
+ def add_build_info(type, file)
184
+ type = type.to_sym
185
+
186
+ @load_info[type] = {} unless @load_info.has_key?(type)
187
+
188
+ components = file.split(File::SEPARATOR)
189
+ provider = components.pop.sub(/\.rb/, '').to_sym
190
+ directory = components.join(File::SEPARATOR)
191
+
192
+ logger.info("Loading corl #{type} plugin #{provider} at #{Time.now}")
193
+
194
+ unless @load_info[type].has_key?(provider)
195
+ data = {
196
+ :type => type,
197
+ :provider => provider,
198
+ :directory => directory,
199
+ :file => file
200
+ }
201
+
202
+ logger.debug("Plugin #{type} loaded: #{data.inspect}")
203
+ @load_info[type][provider] = data
204
+ end
205
+ end
206
+ protected :add_build_info
207
+
208
+ #---
209
+
210
+ def autoload
211
+ logger.info("Autoloading registered plugins at #{Time.now}")
212
+
213
+ @load_info.keys.each do |type|
214
+ logger.debug("Autoloading type: #{type}")
215
+
216
+ @load_info[type].each do |provider, plugin|
217
+ logger.debug("Autoloading provider #{provider} at #{plugin[:directory]}")
218
+
219
+ corl_require(plugin[:directory], provider)
220
+
221
+ @load_info[type][provider][:class] = CORL.class_const([ 'CORL', type, provider ])
222
+ logger.debug("Updated #{type} #{provider} load info: #{@load_info[type][provider].inspect}")
223
+
224
+ # Make sure extensions are listening from the time they are loaded
225
+ create(:extension, provider) if type == :extension # Create a persistent instance
226
+ end
227
+ end
228
+ end
229
+
230
+ #---
231
+
232
+ def create(type, provider, options = {})
233
+ type = type.to_sym
234
+ provider = provider.to_sym
235
+
236
+ unless @types.has_key?(type)
237
+ logger.warn("Plugin type #{type} creation requested but it has not been registered yet")
238
+ return nil
239
+ end
240
+
241
+ options = translate_type(type, options)
242
+ info = @load_info[type][provider] if Util::Data.exists?(@load_info, [ type, provider ])
243
+
244
+ if info
245
+ logger.debug("Plugin information for #{provider} #{type} found. Data: #{info.inspect}")
246
+
247
+ instance_name = "#{provider}_" + CORL.sha1(options)
248
+ options = translate(type, provider, options)
249
+
250
+ @plugins[type] = {} unless @plugins.has_key?(type)
251
+
252
+ unless instance_name && @plugins[type].has_key?(instance_name)
253
+ info[:instance_name] = instance_name
254
+ options[:meta] = Config.new(info).import(Util::Data.hash(options[:meta]))
255
+
256
+ logger.info("Creating new plugin #{provider} #{type} with #{options.inspect}")
257
+
258
+ plugin = CORL.class_const([ 'CORL', type, provider ]).new(type, provider, options)
259
+
260
+ @plugins[type][instance_name] = plugin
261
+ end
262
+ return @plugins[type][instance_name]
263
+ end
264
+
265
+ logger.warn("Plugin information cannot be found for plugin #{type} #{provider}")
266
+ nil
267
+ end
268
+
269
+ #---
270
+
271
+ def get(type, name)
272
+ logger.info("Fetching plugin #{type} #{name}")
273
+
274
+ if @plugins.has_key?(type)
275
+ @plugins[type].each do |instance_name, plugin|
276
+ if plugin.plugin_name.to_s == name.to_s
277
+ logger.debug("Plugin #{type} #{name} found")
278
+ return plugin
279
+ end
280
+ end
281
+ end
282
+ logger.debug("Plugin #{type} #{name} not found")
283
+ nil
284
+ end
285
+
286
+ #---
287
+
288
+ def remove(plugin)
289
+ if plugin && plugin.respond_to?(:plugin_type) && @plugins.has_key?(plugin.plugin_type)
290
+ logger.debug("Removing #{plugin.plugin_type} #{plugin.plugin_name}")
291
+ @plugins[plugin.plugin_type].delete(plugin.plugin_instance_name)
292
+ plugin.terminate if plugin.respond_to?(:terminate)
293
+ else
294
+ logger.warn("Cannot remove plugin: #{plugin.inspect}")
295
+ end
296
+ end
297
+
298
+ #-----------------------------------------------------------------------------
299
+ # Extension hook execution
300
+
301
+ def exec(method, options = {})
302
+ results = nil
303
+
304
+ if CORL.log_level == :hook # To save processing on rendering
305
+ logger.hook("Executing extension hook { #{method} } at #{Time.now} with:\n#{PP.pp(options, '')}\n")
306
+ end
307
+
308
+ extensions = plugins(:extension)
309
+
310
+ extensions.each do |name, plugin|
311
+ provider = plugin.plugin_provider
312
+ result = nil
313
+
314
+ logger.debug("Checking extension #{provider}")
315
+
316
+ if plugin.respond_to?(method)
317
+ results = {} if results.nil?
318
+
319
+ result = plugin.send(method, options)
320
+ logger.info("Completed hook #{method} at #{Time.now} with: #{result.inspect}")
321
+
322
+ if block_given?
323
+ results[provider] = yield(:process, result)
324
+ logger.debug("Processed extension result into: #{results[provider].inspect}")
325
+ end
326
+
327
+ if results[provider].nil?
328
+ logger.debug("Setting extension result to: #{result.inspect}")
329
+ results[provider] = result
330
+ end
331
+ end
332
+ end
333
+
334
+ if ! results.nil? && block_given?
335
+ results = yield(:reduce, results)
336
+ logger.debug("Reducing extension results to: #{results.inspect}")
337
+ else
338
+ logger.debug("Final extension results: #{results.inspect}")
339
+ end
340
+ results
341
+ end
342
+
343
+ #---
344
+
345
+ def config(type, options = {})
346
+ config = Config.ensure(options)
347
+
348
+ logger.debug("Generating #{type} extended configuration from: #{config.export.inspect}")
349
+
350
+ exec("#{type}_config", Config.new(config.export)) do |op, data|
351
+ if op == :reduce
352
+ data.each do |provider, result|
353
+ config.defaults(result)
354
+ end
355
+ nil
356
+ else
357
+ hash(data)
358
+ end
359
+ end
360
+ config.delete(:extension_type)
361
+
362
+ logger.debug("Final extended configuration: #{config.export.inspect}")
363
+ config
364
+ end
365
+
366
+ #---
367
+
368
+ def check(method, options = {})
369
+ config = Config.ensure(options)
370
+
371
+ logger.debug("Checking extension #{method} given: #{config.export.inspect}")
372
+
373
+ success = exec(method, config.import({ :extension_type => :check })) do |op, data|
374
+ if op == :reduce
375
+ ! data.values.include?(false)
376
+ else
377
+ data ? true : false
378
+ end
379
+ end
380
+
381
+ success = success.nil? || success ? true : false
382
+
383
+ logger.debug("Extension #{method} check result: #{success.inspect}")
384
+ success
385
+ end
386
+
387
+ #---
388
+
389
+ def value(method, value, options = {})
390
+ config = Config.ensure(options)
391
+
392
+ logger.debug("Setting extension #{method} value given: #{value.inspect}")
393
+
394
+ exec(method, config.import({ :value => value, :extension_type => :value })) do |op, data|
395
+ if op == :process
396
+ value = data unless data.nil?
397
+ end
398
+ end
399
+
400
+ logger.debug("Extension #{method} retrieved value: #{value.inspect}")
401
+ value
402
+ end
403
+
404
+ #-----------------------------------------------------------------------------
405
+ # Utilities
406
+
407
+ def translate_type(type, info, method = :translate)
408
+ klass = CORL.class_const([ 'CORL', :plugin, type ])
409
+ logger.debug("Executing option translation for: #{klass.inspect}")
410
+
411
+ info = klass.send(method, info) if klass.respond_to?(method)
412
+ info
413
+ end
414
+
415
+ #---
416
+
417
+ def translate(type, provider, info, method = :translate)
418
+ klass = CORL.class_const([ 'CORL', type, provider ])
419
+ logger.debug("Executing option translation for: #{klass.inspect}")
420
+
421
+ info = klass.send(method, info) if klass.respond_to?(method)
422
+ info
423
+ end
424
+ end
425
+ end
@@ -0,0 +1,58 @@
1
+
2
+ module CORL
3
+ module Mixin
4
+ module Action
5
+ module Commit
6
+
7
+ #-----------------------------------------------------------------------------
8
+ # Options
9
+
10
+ def commit_options(parser, optional = true)
11
+ if optional
12
+ parser.option_bool(:commit, false,
13
+ '--commit',
14
+ 'corl.core.mixins.commit.options.commit'
15
+ )
16
+ else
17
+ parser.options[:commit] = true
18
+ end
19
+
20
+ parser.option_bool(:allow_empty, false,
21
+ '--empty',
22
+ 'corl.core.mixins.commit.options.empty'
23
+ )
24
+ parser.option_bool(:propogate, false,
25
+ '--propogate',
26
+ 'corl.core.mixins.commit.options.propogate'
27
+ )
28
+ parser.option_str(:message, '',
29
+ '--message COMMIT_MESSAGE',
30
+ 'corl.core.mixins.commit.options.message'
31
+ )
32
+ parser.option_str(:author, nil,
33
+ '--author COMMIT_AUTHOR',
34
+ 'corl.core.mixins.commit.options.author'
35
+ )
36
+ end
37
+
38
+ #-----------------------------------------------------------------------------
39
+ # Operations
40
+
41
+ def commit(project, files = '.')
42
+ success = true
43
+
44
+ if project && settings[:commit]
45
+ success = project.commit(files, extended_config(:commit, {
46
+ :allow_empty => settings[:allow_empty],
47
+ :message => settings[:message],
48
+ :author => settings[:author],
49
+ :propogate => settings[:propogate]
50
+ }))
51
+ end
52
+ success
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+