coral_core 0.2.3 → 0.2.4
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.
- data/VERSION +1 -1
- data/coral_core.gemspec +2 -2
- data/lib/coral_core/command.rb +24 -16
- data/lib/coral_core/config.rb +40 -2
- data/lib/coral_core/core.rb +3 -1
- data/lib/coral_core/event.rb +8 -6
- data/lib/coral_core/interface.rb +12 -11
- data/lib/coral_core/memory.rb +15 -11
- data/lib/coral_core/repository.rb +30 -22
- data/lib/coral_core/template.rb +1 -1
- data/lib/coral_core/util/data.rb +7 -75
- data/lib/coral_core/util/shell.rb +11 -9
- data/lib/coral_core.rb +44 -7
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/coral_core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "coral_core"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adrian Webb"]
|
12
|
-
s.date = "2013-05-
|
12
|
+
s.date = "2013-05-10"
|
13
13
|
s.description = "= coral_core\n\nThis library provides core data elements and utilities used in other Coral gems.\n\nThe Coral core library contains functionality that is utilized by other\nCoral gems by providing basic utilities like Git, Shell, Disk, and Data\nmanipulation libraries, a UI system, and a core data model that supports\nEvents, Commands, Repositories, and Memory (version controlled JSON \nobjects). This library is only used as a starting point for other systems.\n\nNote: This library is still very early in development!\n\n== Contributing to coral_core\n \n* Check out the latest {major}.{minor} branch to make sure the feature hasn't \n been implemented or the bug hasn't been fixed yet.\n* Check out the issue tracker to make sure someone already hasn't requested \n it and/or contributed it.\n* Fork the project.\n* Start a feature/bugfix branch.\n* Commit and push until you are happy with your contribution.\n* Make sure to add tests for it. This is important so I don't break it in a \n future version unintentionally.\n* Please try not to mess with the Rakefile, version, or history. If you want \n to have your own version, or is otherwise necessary, that is fine, but \n please isolate to its own commit so I can cherry-pick around it.\n\n== Copyright\n\nLicensed under GPLv3. See LICENSE.txt for further details.\n\nCopyright (c) 2013 Adrian Webb <adrian.webb@coraltech.net>\nCoral Technology Group LLC"
|
14
14
|
s.email = "adrian.webb@coraltech.net"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/coral_core/command.rb
CHANGED
@@ -12,22 +12,24 @@ class Command < Core
|
|
12
12
|
# Constructor / Destructor
|
13
13
|
|
14
14
|
def initialize(options = {})
|
15
|
-
|
15
|
+
|
16
16
|
if options.is_a?(String) || options.is_a?(Symbol)
|
17
17
|
options = string(options)
|
18
18
|
options = { :name => options, :command => options }
|
19
19
|
end
|
20
|
+
|
21
|
+
config = Config.ensure(options)
|
20
22
|
|
21
|
-
super(
|
23
|
+
super(config)
|
22
24
|
|
23
25
|
@properties = {}
|
24
26
|
|
25
|
-
self.subcommand =
|
27
|
+
self.subcommand = config.get(:subcommand, nil)
|
26
28
|
|
27
|
-
@name =
|
29
|
+
@name = config.get(:name, '')
|
28
30
|
|
29
|
-
@properties = options
|
30
|
-
@properties[:command] = executable(
|
31
|
+
@properties = config.options
|
32
|
+
@properties[:command] = executable(config)
|
31
33
|
end
|
32
34
|
|
33
35
|
#-----------------------------------------------------------------------------
|
@@ -94,8 +96,10 @@ class Command < Core
|
|
94
96
|
#---
|
95
97
|
|
96
98
|
def subcommand=subcommand
|
97
|
-
|
98
|
-
|
99
|
+
unless Util::Data.empty?(subcommand)
|
100
|
+
@properties[:subcommand] = hash(subcommand)
|
101
|
+
@subcommand = self.class.new(@properties[:subcommand])
|
102
|
+
end
|
99
103
|
end
|
100
104
|
|
101
105
|
#-----------------------------------------------------------------------------
|
@@ -205,8 +209,10 @@ class Command < Core
|
|
205
209
|
#-----------------------------------------------------------------------------
|
206
210
|
|
207
211
|
def exec!(options = {}, overrides = nil)
|
208
|
-
|
209
|
-
|
212
|
+
config = Config.ensure(options)
|
213
|
+
|
214
|
+
config[:ui] = @ui
|
215
|
+
success = Coral::Util::Shell.exec!(build(export, overrides), config) do |line|
|
210
216
|
block_given? ? yield(line) : true
|
211
217
|
end
|
212
218
|
return success
|
@@ -222,14 +228,16 @@ class Command < Core
|
|
222
228
|
# Utilities
|
223
229
|
|
224
230
|
def executable(options)
|
225
|
-
|
226
|
-
|
231
|
+
config = Config.ensure(options)
|
232
|
+
|
233
|
+
if config.get(:coral, false)
|
234
|
+
return 'vagrant coral ' + config[:coral]
|
227
235
|
|
228
|
-
elsif
|
229
|
-
return 'vagrant ' +
|
236
|
+
elsif config.get(:vagrant, false)
|
237
|
+
return 'vagrant ' + config[:vagrant]
|
230
238
|
|
231
|
-
elsif
|
232
|
-
return
|
239
|
+
elsif config.get(:command, false)
|
240
|
+
return config[:command]
|
233
241
|
end
|
234
242
|
end
|
235
243
|
end
|
data/lib/coral_core/config.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
module Coral
|
3
|
-
class Config
|
3
|
+
class Config
|
4
4
|
|
5
5
|
#-----------------------------------------------------------------------------
|
6
6
|
# Global configuration
|
@@ -33,7 +33,7 @@ class Config < Core
|
|
33
33
|
if File.exist?(config_file)
|
34
34
|
config = Hiera::Config.load(config_file)
|
35
35
|
else
|
36
|
-
ui.warning "Config file #{config_file} not found, using Hiera defaults"
|
36
|
+
Coral.ui.warning "Config file #{config_file} not found, using Hiera defaults"
|
37
37
|
end
|
38
38
|
|
39
39
|
config[:logger] = 'puppet'
|
@@ -139,6 +139,44 @@ class Config < Core
|
|
139
139
|
return value
|
140
140
|
end
|
141
141
|
|
142
|
+
#---
|
143
|
+
|
144
|
+
def self.normalize(data, override = nil, options = {})
|
145
|
+
config = Config.ensure(options)
|
146
|
+
results = {}
|
147
|
+
|
148
|
+
unless undef?(override)
|
149
|
+
case data
|
150
|
+
when String, Symbol
|
151
|
+
data = [ data, override ] if data != override
|
152
|
+
when Array
|
153
|
+
data << override unless data.include?(override)
|
154
|
+
when Hash
|
155
|
+
data = [ data, override ]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
case data
|
160
|
+
when String, Symbol
|
161
|
+
results = Config.lookup(data.to_s, {}, config)
|
162
|
+
|
163
|
+
when Array
|
164
|
+
data.each do |item|
|
165
|
+
if item.is_a?(String) || item.is_a?(Symbol)
|
166
|
+
item = Config.lookup(item.to_s, {}, config)
|
167
|
+
end
|
168
|
+
unless undef?(item)
|
169
|
+
results = Util::Data.merge([ results, item ], config)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
when Hash
|
174
|
+
results = data
|
175
|
+
end
|
176
|
+
|
177
|
+
return results
|
178
|
+
end
|
179
|
+
|
142
180
|
#-----------------------------------------------------------------------------
|
143
181
|
# Instance generator
|
144
182
|
|
data/lib/coral_core/core.rb
CHANGED
@@ -11,7 +11,9 @@ class Core
|
|
11
11
|
# Constructor / Destructor
|
12
12
|
|
13
13
|
def initialize(options = {})
|
14
|
-
|
14
|
+
config = Config.ensure(options)
|
15
|
+
|
16
|
+
@@ui = Interface.new(config)
|
15
17
|
end
|
16
18
|
|
17
19
|
#-----------------------------------------------------------------------------
|
data/lib/coral_core/event.rb
CHANGED
@@ -5,9 +5,9 @@ class Event < Core
|
|
5
5
|
#-----------------------------------------------------------------------------
|
6
6
|
# Constructor / Destructor
|
7
7
|
|
8
|
-
def self.instance!(
|
8
|
+
def self.instance!(data = {}, build_hash = false, keep_array = false)
|
9
9
|
group = ( build_hash ? {} : [] )
|
10
|
-
events = build_info(
|
10
|
+
events = build_info(data)
|
11
11
|
|
12
12
|
index = 1
|
13
13
|
events.each do |info|
|
@@ -41,11 +41,13 @@ class Event < Core
|
|
41
41
|
#---
|
42
42
|
|
43
43
|
def initialize(options = {})
|
44
|
-
|
44
|
+
config = Config.ensure(options)
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
@
|
46
|
+
super(config)
|
47
|
+
|
48
|
+
@name = config.get(:name, '')
|
49
|
+
@delegate = config.get(:delegate, nil)
|
50
|
+
@properties = config.options
|
49
51
|
end
|
50
52
|
|
51
53
|
#-----------------------------------------------------------------------------
|
data/lib/coral_core/interface.rb
CHANGED
@@ -33,27 +33,28 @@ class Interface
|
|
33
33
|
if options.is_a?(String)
|
34
34
|
options = { :resource => options, :logger => options }
|
35
35
|
end
|
36
|
+
config = Config.ensure(options)
|
36
37
|
|
37
|
-
if
|
38
|
-
if
|
39
|
-
@logger = Log4r::Logger.new(
|
38
|
+
if config.get(:logger, false)
|
39
|
+
if config[:logger].is_a?(String)
|
40
|
+
@logger = Log4r::Logger.new(config[:logger])
|
40
41
|
else
|
41
|
-
@logger =
|
42
|
+
@logger = config[:logger]
|
42
43
|
end
|
43
44
|
else
|
44
45
|
@logger = Log4r::Logger.new(class_name)
|
45
46
|
end
|
46
47
|
|
47
|
-
@resource =
|
48
|
-
@color =
|
48
|
+
@resource = config.get(:resource, '')
|
49
|
+
@color = config.get(:color, true)
|
49
50
|
|
50
|
-
@printer =
|
51
|
+
@printer = config.get(:printer, :puts)
|
51
52
|
|
52
|
-
@input =
|
53
|
-
@output =
|
54
|
-
@error =
|
53
|
+
@input = config.get(:input, $stdin)
|
54
|
+
@output = config.get(:output, $stdout)
|
55
|
+
@error = config.get(:error, $stderr)
|
55
56
|
|
56
|
-
@delegate =
|
57
|
+
@delegate = config.get(:ui_delegate, nil)
|
57
58
|
end
|
58
59
|
|
59
60
|
#-----------------------------------------------------------------------------
|
data/lib/coral_core/memory.rb
CHANGED
@@ -8,19 +8,21 @@ class Memory < Repository
|
|
8
8
|
# Constructor / Destructor
|
9
9
|
|
10
10
|
def initialize(options = {})
|
11
|
-
|
11
|
+
config = Config.ensure(options)
|
12
|
+
|
13
|
+
super(config)
|
12
14
|
|
13
15
|
@absolute_config_file = ''
|
14
16
|
|
15
|
-
@properties =
|
16
|
-
|
17
|
-
@autoload =
|
18
|
-
@autosave =
|
19
|
-
@autocommit =
|
20
|
-
@commit_message =
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
@properties = config.get(:properties, {})
|
18
|
+
|
19
|
+
@autoload = config.get(:autoload, true)
|
20
|
+
@autosave = config.get(:autosave, true)
|
21
|
+
@autocommit = config.get(:autocommit, true)
|
22
|
+
@commit_message = config.get(:commit_message, 'Saving state')
|
23
|
+
|
24
|
+
self.config_file = config.get(:config_file, '')
|
25
|
+
dbg(self, 'memory')
|
24
26
|
end
|
25
27
|
|
26
28
|
#---
|
@@ -52,7 +54,9 @@ class Memory < Repository
|
|
52
54
|
#---
|
53
55
|
|
54
56
|
def config_file=config_file
|
55
|
-
|
57
|
+
unless Util::Data.empty?(config_file)
|
58
|
+
@config_file = ( config_file.is_a?(Array) ? config_file.join(File::SEPARATOR) : string(config_file) )
|
59
|
+
end
|
56
60
|
|
57
61
|
set_absolute_config_file
|
58
62
|
load if @autoload
|
@@ -6,12 +6,14 @@ class Repository < Core
|
|
6
6
|
# Constructor / Destructor
|
7
7
|
|
8
8
|
def initialize(options = {})
|
9
|
-
|
9
|
+
config = Config.ensure(options)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
@
|
11
|
+
super(config)
|
12
|
+
|
13
|
+
@name = config.get(:name, '')
|
14
|
+
@directory = config.get(:directory, '')
|
15
|
+
@submodule = config.get(:submodule, '')
|
16
|
+
@remote_dir = config.get(:remote_dir, '')
|
15
17
|
|
16
18
|
ensure_git(true)
|
17
19
|
end
|
@@ -53,26 +55,28 @@ class Repository < Core
|
|
53
55
|
#-----------------------------------------------------------------------------
|
54
56
|
|
55
57
|
def set_remote(name, hosts, options = {})
|
58
|
+
config = Config.ensure(options)
|
59
|
+
|
56
60
|
if can_persist?
|
57
61
|
hosts = array(hosts)
|
58
62
|
|
59
63
|
delete_remote(name)
|
60
64
|
return self if hosts.empty?
|
61
65
|
|
62
|
-
if @remote_dir && !
|
63
|
-
|
66
|
+
if @remote_dir && ! config.get(:repo, false)
|
67
|
+
config[:repo] = @remote_dir
|
64
68
|
end
|
65
69
|
|
66
|
-
git.add_remote(name, Git.url(hosts.shift,
|
70
|
+
git.add_remote(name, Git.url(hosts.shift, config[:repo], options))
|
67
71
|
|
68
72
|
if ! hosts.empty?
|
69
73
|
remote = git.remote(name)
|
70
74
|
|
71
|
-
|
75
|
+
config[:add] = true
|
72
76
|
|
73
77
|
hosts.each do |host|
|
74
|
-
git_url = Git.url(host,
|
75
|
-
remote.set_url(git_url, options)
|
78
|
+
git_url = Git.url(host, config[:repo], config.options)
|
79
|
+
remote.set_url(git_url, config.options)
|
76
80
|
end
|
77
81
|
end
|
78
82
|
end
|
@@ -83,7 +87,7 @@ class Repository < Core
|
|
83
87
|
|
84
88
|
def delete_remote(name)
|
85
89
|
if can_persist?
|
86
|
-
remote =
|
90
|
+
remote = git.remote(name)
|
87
91
|
if remote && remote.url && ! remote.url.empty?
|
88
92
|
remote.remove
|
89
93
|
end
|
@@ -95,24 +99,26 @@ class Repository < Core
|
|
95
99
|
# Git operations
|
96
100
|
|
97
101
|
def commit(files = '.', options = {})
|
102
|
+
config = Config.ensure(options)
|
103
|
+
|
98
104
|
if can_persist?
|
99
105
|
time = Time.new.strftime("%Y-%m-%d %H:%M:%S")
|
100
106
|
user = ENV['USER']
|
101
|
-
message = (
|
107
|
+
message = config.get(:message, 'Saving state')
|
102
108
|
|
103
|
-
|
104
|
-
|
109
|
+
config[:author] = config.get(:author, '')
|
110
|
+
config[:allow_empty] = config.get(:allow_empty, false)
|
105
111
|
|
106
112
|
unless user && ! user.empty?
|
107
113
|
user = 'UNKNOWN'
|
108
114
|
end
|
109
115
|
|
110
116
|
array(files).each do |file|
|
111
|
-
|
112
|
-
|
117
|
+
git.add(file) # Get all added and updated files
|
118
|
+
git.add(file, { :update => true }) # Get all deleted files
|
113
119
|
end
|
114
120
|
|
115
|
-
|
121
|
+
git.commit("#{time} by <#{user}> - #{message}", config.options)
|
116
122
|
end
|
117
123
|
return self
|
118
124
|
end
|
@@ -120,19 +126,21 @@ class Repository < Core
|
|
120
126
|
#-----------------------------------------------------------------------------
|
121
127
|
|
122
128
|
def push!(remote = 'origin', options = {})
|
129
|
+
config = Config.ensure(options)
|
130
|
+
|
123
131
|
if can_persist?
|
124
|
-
branch
|
125
|
-
tags
|
132
|
+
branch = config.get(:branch, 'master')
|
133
|
+
tags = config.get(:tags, false)
|
126
134
|
|
127
135
|
return Coral::Command.new({
|
128
136
|
:command => :git,
|
129
|
-
:data => { 'git-dir=' =>
|
137
|
+
:data => { 'git-dir=' => git.repo.to_s },
|
130
138
|
:subcommand => {
|
131
139
|
:command => :push,
|
132
140
|
:flags => ( tags ? :tags : '' ),
|
133
141
|
:args => [ remote, branch ]
|
134
142
|
}
|
135
|
-
}).exec!(
|
143
|
+
}).exec!(config) do |line|
|
136
144
|
block_given? ? yield(line) : true
|
137
145
|
end
|
138
146
|
end
|
data/lib/coral_core/template.rb
CHANGED
data/lib/coral_core/util/data.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Coral
|
3
3
|
module Util
|
4
|
-
class Data
|
4
|
+
class Data
|
5
5
|
|
6
6
|
#-----------------------------------------------------------------------------
|
7
7
|
# Type checking
|
@@ -136,53 +136,14 @@ class Data < Core
|
|
136
136
|
#dbg(value, 'value')
|
137
137
|
return value
|
138
138
|
end
|
139
|
-
|
140
|
-
#---
|
141
139
|
|
142
|
-
def self.normalize(data, override = nil, options = {})
|
143
|
-
config = Config.ensure(options)
|
144
|
-
results = {}
|
145
|
-
|
146
|
-
unless undef?(override)
|
147
|
-
case data
|
148
|
-
when String, Symbol
|
149
|
-
data = [ data, override ] if data != override
|
150
|
-
when Array
|
151
|
-
data << override unless data.include?(override)
|
152
|
-
when Hash
|
153
|
-
data = [ data, override ]
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
case data
|
158
|
-
when String, Symbol
|
159
|
-
results = Config.lookup(data.to_s, {}, config)
|
160
|
-
|
161
|
-
when Array
|
162
|
-
data.each do |item|
|
163
|
-
if item.is_a?(String) || item.is_a?(Symbol)
|
164
|
-
item = Config.lookup(item.to_s, {}, config)
|
165
|
-
end
|
166
|
-
unless undef?(item)
|
167
|
-
results = merge([ results, item ], config)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
when Hash
|
172
|
-
results = data
|
173
|
-
end
|
174
|
-
|
175
|
-
return results
|
176
|
-
end
|
177
|
-
|
178
140
|
#---
|
179
141
|
|
180
142
|
def self.interpolate(value, scope, options = {})
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
flags = config.get(:flags, '')
|
143
|
+
|
144
|
+
pattern = ( options.has_key?(:pattern) ? options[:pattern] : '\$(\{)?([a-zA-Z0-9\_\-]+)(\})?' )
|
145
|
+
group = ( options.has_key?(:var_group) ? options[:var_group] : 2 )
|
146
|
+
flags = ( options.has_key?(:flags) ? options[:flags] : '' )
|
186
147
|
|
187
148
|
if scope.is_a?(Hash)
|
188
149
|
regexp = Regexp.new(pattern, flags.split(''))
|
@@ -195,7 +156,7 @@ class Data < Core
|
|
195
156
|
#dbg(matches, 'matches')
|
196
157
|
|
197
158
|
unless matches.nil?
|
198
|
-
replacement = scope.search(matches[group],
|
159
|
+
replacement = scope.search(matches[group], options)
|
199
160
|
result = item.gsub(matches[0], replacement) unless replacement.nil?
|
200
161
|
end
|
201
162
|
return result
|
@@ -213,7 +174,7 @@ class Data < Core
|
|
213
174
|
#dbg(value, 'interpolate (hash) -> init')
|
214
175
|
value.each do |key, data|
|
215
176
|
#dbg(data, "interpolate (#{key}) -> data")
|
216
|
-
value[key] = interpolate(data, scope,
|
177
|
+
value[key] = interpolate(data, scope, options)
|
217
178
|
end
|
218
179
|
end
|
219
180
|
end
|
@@ -223,32 +184,3 @@ class Data < Core
|
|
223
184
|
end
|
224
185
|
end
|
225
186
|
end
|
226
|
-
|
227
|
-
#-------------------------------------------------------------------------------
|
228
|
-
# Data type alterations
|
229
|
-
|
230
|
-
class Hash
|
231
|
-
def search(search_key, options = {})
|
232
|
-
config = Coral::Config.ensure(options)
|
233
|
-
value = nil
|
234
|
-
|
235
|
-
recurse = config.get(:recurse, false)
|
236
|
-
recurse_level = config.get(:recurse_level, -1)
|
237
|
-
|
238
|
-
self.each do |key, data|
|
239
|
-
if key == search_key
|
240
|
-
value = data
|
241
|
-
|
242
|
-
elsif data.is_a?(Hash) &&
|
243
|
-
recurse && (recurse_level == -1 || recurse_level > 0)
|
244
|
-
|
245
|
-
recurse_level -= 1 unless recurse_level == -1
|
246
|
-
value = value.search(search_key,
|
247
|
-
Coral::Config.new(config).set(:recurse_level, recurse_level)
|
248
|
-
)
|
249
|
-
end
|
250
|
-
break unless value.nil?
|
251
|
-
end
|
252
|
-
return value
|
253
|
-
end
|
254
|
-
end
|
@@ -7,18 +7,20 @@ class Shell < Core
|
|
7
7
|
# Utilities
|
8
8
|
|
9
9
|
def self.exec!(command, options = {})
|
10
|
-
|
11
|
-
tries = ( options[:tries] ? options[:tries].to_i : min )
|
12
|
-
tries = ( min > tries ? min : tries )
|
10
|
+
config = Config.ensure(options)
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
error_suffix = ( options[:error_suffix] ? options[:error_suffix] : '' )
|
12
|
+
min = config.get(:min, 1).to_i
|
13
|
+
tries = config.get(:tries, min).to_i
|
14
|
+
tries = ( min > tries ? min : tries )
|
18
15
|
|
19
|
-
|
16
|
+
info_prefix = config.get(:info_prefix, '')
|
17
|
+
info_suffix = config.get(:info_suffix, '')
|
18
|
+
error_prefix = config.get(:error_prefix, '')
|
19
|
+
error_suffix = config.get(:error_suffix, '')
|
20
20
|
|
21
|
-
|
21
|
+
ui = config.get(:ui, @@ui)
|
22
|
+
|
23
|
+
conditions = Coral::Event.instance(config.get(:exit, {}), true)
|
22
24
|
|
23
25
|
$stdout.sync = true
|
24
26
|
$stderr.sync = true
|
data/lib/coral_core.rb
CHANGED
@@ -11,13 +11,8 @@ require 'hiera_backend.rb'
|
|
11
11
|
|
12
12
|
#---
|
13
13
|
|
14
|
-
# Include core
|
15
|
-
[ :
|
16
|
-
require File.join('coral_core', name.to_s + ".rb")
|
17
|
-
end
|
18
|
-
|
19
|
-
# Include utilities
|
20
|
-
[ :git, :data, :disk, :shell ].each do |name|
|
14
|
+
# Include pre core utilities (no internal dependencies)
|
15
|
+
[ :git, :data ].each do |name|
|
21
16
|
require File.join('coral_core', 'util', name.to_s + ".rb")
|
22
17
|
end
|
23
18
|
|
@@ -26,6 +21,19 @@ Dir.glob(File.join(home, 'coral_core', 'util', 'git', '*.rb')).each do |file|
|
|
26
21
|
require file
|
27
22
|
end
|
28
23
|
|
24
|
+
# Include core
|
25
|
+
[ :config, :interface, :core, :resource, :template ].each do |name|
|
26
|
+
require File.join('coral_core', name.to_s + ".rb")
|
27
|
+
end
|
28
|
+
|
29
|
+
# Include post core utilities
|
30
|
+
# ( normally inherit from core and have no reverse dependencies with
|
31
|
+
# core classes )
|
32
|
+
#
|
33
|
+
[ :disk, :shell ].each do |name|
|
34
|
+
require File.join('coral_core', 'util', name.to_s + ".rb")
|
35
|
+
end
|
36
|
+
|
29
37
|
# Include data model
|
30
38
|
[ :event, :command, :repository, :memory ].each do |name|
|
31
39
|
require File.join('coral_core', name.to_s + ".rb")
|
@@ -117,3 +125,32 @@ module Kernel
|
|
117
125
|
puts '<<'
|
118
126
|
end
|
119
127
|
end
|
128
|
+
|
129
|
+
#-------------------------------------------------------------------------------
|
130
|
+
# Data type alterations
|
131
|
+
|
132
|
+
class Hash
|
133
|
+
def search(search_key, options = {})
|
134
|
+
config = Coral::Config.ensure(options)
|
135
|
+
value = nil
|
136
|
+
|
137
|
+
recurse = config.get(:recurse, false)
|
138
|
+
recurse_level = config.get(:recurse_level, -1)
|
139
|
+
|
140
|
+
self.each do |key, data|
|
141
|
+
if key == search_key
|
142
|
+
value = data
|
143
|
+
|
144
|
+
elsif data.is_a?(Hash) &&
|
145
|
+
recurse && (recurse_level == -1 || recurse_level > 0)
|
146
|
+
|
147
|
+
recurse_level -= 1 unless recurse_level == -1
|
148
|
+
value = value.search(search_key,
|
149
|
+
Coral::Config.new(config).set(:recurse_level, recurse_level)
|
150
|
+
)
|
151
|
+
end
|
152
|
+
break unless value.nil?
|
153
|
+
end
|
154
|
+
return value
|
155
|
+
end
|
156
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coral_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adrian Webb
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-05-
|
18
|
+
date: 2013-05-10 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: git
|