coral_core 0.2.30 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +2 -8
  3. data/Gemfile.lock +15 -86
  4. data/Rakefile +1 -3
  5. data/VERSION +1 -1
  6. data/coral_core.gemspec +12 -102
  7. metadata +18 -239
  8. data/lib/coral/command/shell.rb +0 -140
  9. data/lib/coral/machine/fog.rb +0 -215
  10. data/lib/coral/network/default.rb +0 -26
  11. data/lib/coral/node/rackspace.rb +0 -23
  12. data/lib/coral_core/config/collection.rb +0 -57
  13. data/lib/coral_core/config/options.rb +0 -70
  14. data/lib/coral_core/config/project.rb +0 -225
  15. data/lib/coral_core/config.rb +0 -329
  16. data/lib/coral_core/core.rb +0 -58
  17. data/lib/coral_core/event/puppet_event.rb +0 -98
  18. data/lib/coral_core/event/regexp_event.rb +0 -55
  19. data/lib/coral_core/event.rb +0 -170
  20. data/lib/coral_core/mixin/config_collection.rb +0 -52
  21. data/lib/coral_core/mixin/config_ops.rb +0 -51
  22. data/lib/coral_core/mixin/config_options.rb +0 -38
  23. data/lib/coral_core/mixin/lookup.rb +0 -211
  24. data/lib/coral_core/mixin/macro/object_interface.rb +0 -292
  25. data/lib/coral_core/mixin/macro/plugin_interface.rb +0 -277
  26. data/lib/coral_core/mixin/settings.rb +0 -46
  27. data/lib/coral_core/mixin/sub_config.rb +0 -208
  28. data/lib/coral_core/mod/hash.rb +0 -29
  29. data/lib/coral_core/mod/hiera_backend.rb +0 -63
  30. data/lib/coral_core/plugin/command.rb +0 -95
  31. data/lib/coral_core/plugin/machine.rb +0 -152
  32. data/lib/coral_core/plugin/network.rb +0 -24
  33. data/lib/coral_core/plugin/node.rb +0 -184
  34. data/lib/coral_core/plugin.rb +0 -261
  35. data/lib/coral_core/plugin_base.rb +0 -147
  36. data/lib/coral_core/repository.rb +0 -553
  37. data/lib/coral_core/resource.rb +0 -243
  38. data/lib/coral_core/template/environment.rb +0 -72
  39. data/lib/coral_core/template/json.rb +0 -13
  40. data/lib/coral_core/template/wrapper.rb +0 -13
  41. data/lib/coral_core/template/yaml.rb +0 -13
  42. data/lib/coral_core/template.rb +0 -92
  43. data/lib/coral_core/util/cli.rb +0 -293
  44. data/lib/coral_core/util/data.rb +0 -389
  45. data/lib/coral_core/util/disk.rb +0 -105
  46. data/lib/coral_core/util/git.rb +0 -40
  47. data/lib/coral_core/util/interface.rb +0 -190
  48. data/lib/coral_core/util/process.rb +0 -43
  49. data/lib/coral_core/util/shell.rb +0 -183
  50. data/lib/coral_core.rb +0 -375
  51. data/locales/en.yml +0 -8
  52. data/spec/coral_core/interface_spec.rb +0 -489
  53. data/spec/coral_mock_input.rb +0 -29
  54. data/spec/coral_test_kernel.rb +0 -22
  55. data/spec/spec_helper.rb +0 -15
@@ -1,70 +0,0 @@
1
-
2
- module Coral
3
- class Config
4
- class Options
5
-
6
- #-----------------------------------------------------------------------------
7
- # Property accessors / modifiers
8
-
9
- @@options = {}
10
-
11
- #---
12
-
13
- def self.contexts(contexts = [], hierarchy = [])
14
- contexts = [ 'all', contexts ].flatten
15
-
16
- unless hierarchy.is_a?(Array)
17
- hierarchy = ( ! Util::Data.empty?(hierarchy) ? [ hierarchy ].flatten : [] )
18
- end
19
-
20
- hierarchy.each do |group|
21
- group_contexts = Util::Data.prefix(group, contexts)
22
- contexts = [ contexts, group_contexts ].flatten
23
- end
24
-
25
- return contexts
26
- end
27
-
28
- #---
29
-
30
- def self.get(contexts, force = true)
31
- options = {}
32
-
33
- unless contexts.is_a?(Array)
34
- contexts = ( ! Util::Data.empty?(contexts) ? [ contexts ].flatten : [] )
35
- end
36
- contexts.each do |name|
37
- name = name.to_sym
38
- if @@options.has_key?(name)
39
- options = Util::Data.merge([ options, @@options[name] ], force)
40
- end
41
- end
42
- return options
43
- end
44
-
45
- #---
46
-
47
- def self.set(contexts, options, force = true)
48
- unless contexts.is_a?(Array)
49
- contexts = ( ! Util::Data.empty?(contexts) ? [ contexts ].flatten : [] )
50
- end
51
- contexts.each do |name|
52
- name = name.to_sym
53
- current_options = ( @@options.has_key?(name) ? @@options[name] : {} )
54
- @@options[name] = Util::Data.merge([ current_options, Config.symbol_map(options) ], force)
55
- end
56
- end
57
-
58
- #---
59
-
60
- def self.clear(contexts)
61
- unless contexts.is_a?(Array)
62
- contexts = [ contexts ]
63
- end
64
- contexts.each do |name|
65
- @@options.delete(name.to_sym)
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,225 +0,0 @@
1
-
2
- module Coral
3
- class Config
4
- class Project < Config
5
-
6
- include Mixin::SubConfig
7
-
8
- #-----------------------------------------------------------------------------
9
-
10
- def initialize(data = {}, defaults = {}, force = true)
11
- super(data, defaults, force)
12
-
13
- init_subconfig(true)
14
-
15
- unless _get(:project)
16
- _set(:project, Repository.open(_delete(:directory, Dir.pwd), {
17
- :origin => _delete(:origin),
18
- :revision => _delete(:revision)
19
- }))
20
- end
21
-
22
- _init(:autoload, true)
23
- _init(:autosave, true)
24
- _init(:autocommit, true)
25
- _init(:commit_message, 'Saving state')
26
-
27
- self.config_file = _get(:config_file, '')
28
- end
29
-
30
- #---
31
-
32
- def self.finalize(file_name)
33
- proc do
34
- Util::Disk.close(file_name)
35
- end
36
- end
37
-
38
- #---
39
-
40
- #def inspect
41
- # "#<#{self.class}: #{@absolute_config_file}>"
42
- #end
43
-
44
- #-----------------------------------------------------------------------------
45
- # Checks
46
-
47
- def can_persist?
48
- success = project.can_persist?
49
- success = false if Util::Data.empty?(@absolute_config_file)
50
- return success
51
- end
52
-
53
- #-----------------------------------------------------------------------------
54
- # Property accessors / modifiers
55
-
56
- def autoload(default = false)
57
- return _get(:autoload, default)
58
- end
59
-
60
- #---
61
-
62
- def autoload=autoload
63
- _set(:autoload, test(autoload))
64
- end
65
-
66
- #---
67
-
68
- def autosave(default = false)
69
- return _get(:autosave, default)
70
- end
71
-
72
- #---
73
-
74
- def autosave=autosave
75
- _set(:autosave, test(autosave))
76
- end
77
-
78
- #---
79
-
80
- def autocommit(default = false)
81
- return _get(:autocommit, default)
82
- end
83
-
84
- #---
85
-
86
- def autocommit=autocommit
87
- _set(:autocommit, test(autocommit))
88
- end
89
-
90
- #---
91
-
92
- def commit_message(default = false)
93
- return _get(:commit_message, default)
94
- end
95
-
96
- #---
97
-
98
- def commit_message=commit_message
99
- _set(:commit_message, string(commit_message))
100
- end
101
-
102
- #---
103
-
104
- def project(default = nil)
105
- return _get(:project, default)
106
- end
107
-
108
- #---
109
-
110
- def config_file(default = nil)
111
- return _get(:config_file, default)
112
- end
113
-
114
- #---
115
-
116
- def config_file=file
117
- unless Util::Data.empty?(file)
118
- _set(:config_file, Util::Disk.filename(file))
119
- end
120
- set_absolute_config_file
121
- end
122
-
123
- #---
124
-
125
- def set_absolute_config_file
126
- if Util::Data.empty?(project.directory) || Util::Data.empty?(config_file)
127
- @absolute_config_file = ''
128
- else
129
- @absolute_config_file = File.join(project.directory, config_file)
130
- ObjectSpace.define_finalizer(self, self.class.finalize(@absolute_config_file))
131
- end
132
- load if autoload
133
- return self
134
- end
135
- protected :set_absolute_config_file
136
-
137
- #---
138
-
139
- def set_location(directory)
140
- if directory && directory.is_a?(Coral::Repository)
141
- project.set_location(directory.directory)
142
- elsif directory && directory.is_a?(String) || directory.is_a?(Symbol)
143
- project.set_location(directory.to_s)
144
- end
145
- set_absolute_config_file if directory
146
- end
147
-
148
- #-----------------------------------------------------------------------------
149
-
150
- def set(keys, value = '', options = {})
151
- super(keys, value)
152
- save(options) if autosave
153
- return self
154
- end
155
-
156
- #---
157
-
158
- def delete(keys, options = {})
159
- super(keys)
160
- save(options) if autosave
161
- return self
162
- end
163
-
164
- #---
165
-
166
- def clear(options = {})
167
- super
168
- save(options) if autosave
169
- return self
170
- end
171
-
172
- #-----------------------------------------------------------------------------
173
- # Import / Export
174
-
175
- def import(properties, options = {})
176
- super(properties, options)
177
- save(options) if autosave
178
- return self
179
- end
180
-
181
- #-----------------------------------------------------------------------------
182
- # Configuration loading / saving
183
-
184
- def load(options = {})
185
- local_config = Config.ensure(options)
186
-
187
- if can_persist? && File.exists?(@absolute_config_file)
188
- raw = Util::Disk.read(@absolute_config_file)
189
- if raw && ! raw.empty?
190
- config.clear if local_config.get(:override, false)
191
- config.import(Util::Data.parse_json(raw), local_config)
192
- end
193
- end
194
- return self
195
- end
196
-
197
- #---
198
-
199
- def save(options = {})
200
- local_config = Config.ensure(options)
201
-
202
- if can_persist?
203
- rendering = Util::Data.to_json(config.export, local_config.get(:pretty, true))
204
- if rendering && ! rendering.empty?
205
- Util::Disk.write(@absolute_config_file, rendering)
206
- project.commit(@absolute_config_file, local_config) if autocommit
207
- end
208
- end
209
- return self
210
- end
211
-
212
- #---
213
-
214
- def rm(options = {})
215
- local_config = Config.ensure(options)
216
-
217
- if can_persist?
218
- config.clear
219
- File.delete(@absolute_config_file)
220
- project.commit(@absolute_config_file, local_config) if autocommit
221
- end
222
- end
223
- end
224
- end
225
- end
@@ -1,329 +0,0 @@
1
-
2
- module Coral
3
- class Config
4
-
5
- #-----------------------------------------------------------------------------
6
- # Global interface
7
-
8
- extend Mixin::ConfigOptions
9
- extend Mixin::ConfigCollection
10
- extend Mixin::Lookup
11
- extend Mixin::ConfigOps
12
-
13
- #-----------------------------------------------------------------------------
14
- # Instance generators
15
-
16
- def self.ensure(config)
17
- case config
18
- when Coral::Config
19
- return config
20
- when Hash
21
- return new(config)
22
- end
23
- return new
24
- end
25
-
26
- #---
27
-
28
- def self.init(options, contexts = [], hierarchy = [], defaults = {})
29
- contexts = contexts(contexts, hierarchy)
30
- config = new(get_options(contexts), defaults)
31
- config.import(options) unless Util::Data.empty?(options)
32
- return config
33
- end
34
-
35
- #---
36
-
37
- def self.init_flat(options, contexts = [], defaults = {})
38
- return init(options, contexts, [], defaults)
39
- end
40
-
41
- #-----------------------------------------------------------------------------
42
- # Constructor / Destructor
43
-
44
- def initialize(data = {}, defaults = {}, force = true)
45
- @force = force
46
- @properties = {}
47
-
48
- if defaults.is_a?(Hash) && ! defaults.empty?
49
- defaults = symbol_map(defaults)
50
- end
51
-
52
- case data
53
- when Coral::Config
54
- @properties = Util::Data.merge([ defaults, data.export ], force)
55
- when Hash
56
- @properties = {}
57
- if data.is_a?(Hash)
58
- @properties = Util::Data.merge([ defaults, symbol_map(data) ], force)
59
- end
60
- end
61
- end
62
-
63
- #---
64
-
65
- #def inspect
66
- # "#<#{self.class}: >"
67
- #end
68
-
69
- #-----------------------------------------------------------------------------
70
- # Property accessors / modifiers
71
-
72
- def fetch(data, keys, default = nil, format = false)
73
- if keys.is_a?(String) || keys.is_a?(Symbol)
74
- keys = [ keys ]
75
- end
76
- key = keys.shift.to_sym
77
-
78
- if data.has_key?(key)
79
- value = data[key]
80
-
81
- if keys.empty?
82
- return filter(value, format)
83
- else
84
- return fetch(data[key], keys, default, format)
85
- end
86
- end
87
- return filter(default, format)
88
- end
89
- protected :fetch
90
-
91
- #---
92
-
93
- def modify(data, keys, value = nil)
94
- if keys.is_a?(String) || keys.is_a?(Symbol)
95
- keys = [ keys ]
96
- end
97
-
98
- key = keys.shift.to_sym
99
- has_key = data.has_key?(key)
100
- existing = {
101
- :key => key,
102
- :value => ( has_key ? data[key] : nil )
103
- }
104
-
105
- if keys.empty?
106
- existing[:value] = data[key] if has_key
107
-
108
- if value.nil?
109
- data.delete(key) if has_key
110
- else
111
- data[key] = value
112
- end
113
- else
114
- data[key] = {} unless has_key
115
- existing = modify(data[key], keys, value)
116
- end
117
-
118
- return existing
119
- end
120
- protected :modify
121
-
122
- #---
123
-
124
- def get(keys, default = nil, format = false)
125
- return fetch(@properties, array(keys).flatten, default, format)
126
- end
127
-
128
- #---
129
-
130
- def [](name, default = nil, format = false)
131
- get(name, default, format)
132
- end
133
-
134
- #---
135
-
136
- def get_array(keys, default = [])
137
- return get(keys, default, :array)
138
- end
139
-
140
- #---
141
-
142
- def get_hash(keys, default = {})
143
- return get(keys, default, :hash)
144
- end
145
-
146
- #---
147
-
148
- def init(keys, default = nil)
149
- return set(keys, get(keys, default))
150
- end
151
-
152
- #---
153
-
154
- def set(keys, value)
155
- modify(@properties, array(keys).flatten, value)
156
- return self
157
- end
158
-
159
- #---
160
-
161
- def []=(name, value)
162
- set(name, value)
163
- end
164
-
165
- #---
166
-
167
- def delete(keys, default = nil)
168
- existing = modify(@properties, array(keys).flatten, nil)
169
- return existing[:value] if existing[:value]
170
- return default
171
- end
172
-
173
- #---
174
-
175
- def clear
176
- @properties = {}
177
- return self
178
- end
179
-
180
- #-----------------------------------------------------------------------------
181
- # Import / Export
182
-
183
- def import_base(properties, options = {})
184
- config = Config.new(options, { :force => @force }).set(:context, :hash)
185
- import_type = config.get(:import_type, :override)
186
-
187
- case properties
188
- when Hash
189
- data = [ @properties, symbol_map(properties) ]
190
- data = data.reverse if import_type != :override
191
-
192
- @properties = Util::Data.merge(data, config)
193
-
194
- when String, Symbol
195
- properties = lookup(properties.to_s, {}, config)
196
-
197
- data = [ @properties, symbol_map(properties) ]
198
- data = data.reverse if import_type != :override
199
-
200
- @properties = Util::Data.merge(data, config)
201
-
202
- when Array
203
- properties.each do |item|
204
- import_base(item, config)
205
- end
206
- end
207
-
208
- return self
209
- end
210
- protected :import_base
211
-
212
- #---
213
-
214
- def import(properties, options = {})
215
- return import_base(properties, options)
216
- end
217
-
218
- #---
219
-
220
- def defaults(defaults, options = {})
221
- config = new(options).set(:import_type, :default)
222
- return import_base(defaults, config)
223
- end
224
-
225
- #---
226
-
227
- def export
228
- return @properties
229
- end
230
-
231
- #-----------------------------------------------------------------------------
232
- # Utilities
233
-
234
- def self.symbol_map(data)
235
- return Util::Data.symbol_map(data)
236
- end
237
-
238
- #---
239
-
240
- def symbol_map(data)
241
- return self.class.symbol_map(data)
242
- end
243
-
244
- #---
245
-
246
- def self.string_map(data)
247
- return Util::Data.string_map(data)
248
- end
249
-
250
- #---
251
-
252
- def string_map(data)
253
- return self.class.string_map(data)
254
- end
255
-
256
- #-----------------------------------------------------------------------------
257
-
258
- def self.filter(data, method = false)
259
- return Util::Data.filter(data, method)
260
- end
261
-
262
- #---
263
-
264
- def filter(data, method = false)
265
- return self.class.filter(data, method)
266
- end
267
-
268
- #-----------------------------------------------------------------------------
269
-
270
- def self.array(data, default = [], split_string = false)
271
- return Util::Data.array(data, default, split_string)
272
- end
273
-
274
- #---
275
-
276
- def array(data, default = [], split_string = false)
277
- return self.class.array(data, default, split_string)
278
- end
279
-
280
- #---
281
-
282
- def self.hash(data, default = {})
283
- data = data.export if data.is_a?(Coral::Config)
284
- return Util::Data.hash(data, default)
285
- end
286
-
287
- #---
288
-
289
- def hash(data, default = {})
290
- return self.class.hash(data, default)
291
- end
292
-
293
- #---
294
-
295
- def self.string(data, default = '')
296
- return Util::Data.string(data, default)
297
- end
298
-
299
- #---
300
-
301
- def string(data, default = '')
302
- return self.class.string(data, default)
303
- end
304
-
305
- #---
306
-
307
- def self.symbol(data, default = :undefined)
308
- return Util::Data.symbol(data, default)
309
- end
310
-
311
- #---
312
-
313
- def symbol(data, default = :undefined)
314
- return self.class.symbol(data, default)
315
- end
316
-
317
- #---
318
-
319
- def self.test(data)
320
- return Util::Data.test(data)
321
- end
322
-
323
- #---
324
-
325
- def test(data)
326
- return self.class.test(data)
327
- end
328
- end
329
- end