coral_core 0.2.23 → 0.2.24
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitmodules +12 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +39 -0
- data/Rakefile +79 -0
- data/VERSION +1 -0
- data/coral_core.gemspec +102 -0
- data/lib/coral_core.rb +260 -0
- data/lib/coral_core/command.rb +244 -0
- data/lib/coral_core/config.rb +360 -0
- data/lib/coral_core/core.rb +212 -0
- data/lib/coral_core/event.rb +170 -0
- data/lib/coral_core/event/regexp_event.rb +55 -0
- data/lib/coral_core/interface.rb +180 -0
- data/lib/coral_core/memory.rb +226 -0
- data/lib/coral_core/repository.rb +164 -0
- data/lib/coral_core/resource.rb +243 -0
- data/lib/coral_core/template.rb +92 -0
- data/lib/coral_core/template/environment.rb +72 -0
- data/lib/coral_core/template/json.rb +13 -0
- data/lib/coral_core/template/wrapper.rb +13 -0
- data/lib/coral_core/template/yaml.rb +13 -0
- data/lib/coral_core/util/data.rb +219 -0
- data/lib/coral_core/util/disk.rb +92 -0
- data/lib/coral_core/util/git.rb +15 -0
- data/lib/coral_core/util/git/base.rb +58 -0
- data/lib/coral_core/util/git/lib.rb +82 -0
- data/lib/coral_core/util/git/remote.rb +12 -0
- data/lib/coral_core/util/shell.rb +183 -0
- data/lib/hiera_backend.rb +63 -0
- data/spec/coral_core/interface_spec.rb +489 -0
- data/spec/coral_mock_input.rb +29 -0
- data/spec/coral_test_kernel.rb +22 -0
- data/spec/spec_helper.rb +15 -0
- metadata +38 -4
data/.document
ADDED
data/.gitmodules
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
[submodule "lib/dependency/git"]
|
2
|
+
path = lib/dependency/git
|
3
|
+
url = git://github.com/schacon/ruby-git.git
|
4
|
+
[submodule "lib/dependency/json"]
|
5
|
+
path = lib/dependency/json
|
6
|
+
url = git://github.com/flori/json.git
|
7
|
+
[submodule "lib/dependency/log4r"]
|
8
|
+
path = lib/dependency/log4r
|
9
|
+
url = git://github.com/colbygk/log4r.git
|
10
|
+
[submodule "lib/dependency/deep_merge"]
|
11
|
+
path = lib/dependency/deep_merge
|
12
|
+
url = git://github.com/danielsdeleo/deep_merge.git
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "log4r", "~> 1.1"
|
4
|
+
gem "deep_merge", "~> 1.0"
|
5
|
+
gem "json", ">= 1.4"
|
6
|
+
gem "git", "= 1.2.5"
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem "bundler", "~> 1.2"
|
10
|
+
gem "jeweler", "~> 1.8"
|
11
|
+
gem "rspec", "~> 2.10"
|
12
|
+
gem "rdoc", "~> 3.12"
|
13
|
+
gem "yard", "~> 0.8"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
deep_merge (1.0.0)
|
5
|
+
diff-lcs (1.2.4)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.8.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rdoc
|
12
|
+
json (1.8.0)
|
13
|
+
log4r (1.1.10)
|
14
|
+
rake (10.0.4)
|
15
|
+
rdoc (3.12.2)
|
16
|
+
json (~> 1.4)
|
17
|
+
rspec (2.13.0)
|
18
|
+
rspec-core (~> 2.13.0)
|
19
|
+
rspec-expectations (~> 2.13.0)
|
20
|
+
rspec-mocks (~> 2.13.0)
|
21
|
+
rspec-core (2.13.1)
|
22
|
+
rspec-expectations (2.13.0)
|
23
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
24
|
+
rspec-mocks (2.13.1)
|
25
|
+
yard (0.8.6.1)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.2)
|
32
|
+
deep_merge (~> 1.0)
|
33
|
+
git (= 1.2.5)
|
34
|
+
jeweler (~> 1.8)
|
35
|
+
json (>= 1.4)
|
36
|
+
log4r (~> 1.1)
|
37
|
+
rdoc (~> 3.12)
|
38
|
+
rspec (~> 2.10)
|
39
|
+
yard (~> 0.8)
|
data/Rakefile
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'bundler'
|
6
|
+
require 'jeweler'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
require 'rdoc/task'
|
9
|
+
require 'yard'
|
10
|
+
|
11
|
+
require './lib/coral_core.rb'
|
12
|
+
|
13
|
+
#-------------------------------------------------------------------------------
|
14
|
+
# Dependencies
|
15
|
+
|
16
|
+
begin
|
17
|
+
Bundler.setup(:default, :development)
|
18
|
+
rescue Bundler::BundlerError => e
|
19
|
+
$stderr.puts e.message
|
20
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
21
|
+
exit e.status_code
|
22
|
+
end
|
23
|
+
|
24
|
+
#-------------------------------------------------------------------------------
|
25
|
+
# Gem specification
|
26
|
+
|
27
|
+
Jeweler::Tasks.new do |gem|
|
28
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
29
|
+
gem.name = "coral_core"
|
30
|
+
gem.homepage = "http://github.com/coraltech/ruby-coral_core"
|
31
|
+
gem.rubyforge_project = 'coral_core'
|
32
|
+
gem.license = "GPLv3"
|
33
|
+
gem.email = "adrian.webb@coraltech.net"
|
34
|
+
gem.authors = ["Adrian Webb"]
|
35
|
+
gem.summary = %Q{Provides core data elements and utilities used in other Coral gems}
|
36
|
+
gem.description = File.read('README.rdoc')
|
37
|
+
gem.required_ruby_version = '>= 1.8.1'
|
38
|
+
gem.has_rdoc = true
|
39
|
+
gem.rdoc_options << '--title' << 'Coral Core library' <<
|
40
|
+
'--main' << 'README.rdoc' <<
|
41
|
+
'--line-numbers'
|
42
|
+
|
43
|
+
gem.files.exclude 'lib/dependency'
|
44
|
+
|
45
|
+
# Dependencies defined in Gemfile
|
46
|
+
end
|
47
|
+
|
48
|
+
Jeweler::RubygemsDotOrgTasks.new
|
49
|
+
|
50
|
+
#-------------------------------------------------------------------------------
|
51
|
+
# Testing
|
52
|
+
|
53
|
+
RSpec::Core::RakeTask.new(:spec, :tag) do |spec, task_args|
|
54
|
+
options = []
|
55
|
+
options << "--tag #{task_args[:tag]}" if task_args.is_a?(Array) && ! task_args[:tag].to_s.empty?
|
56
|
+
spec.rspec_opts = options.join(' ')
|
57
|
+
end
|
58
|
+
|
59
|
+
task :default => :spec
|
60
|
+
|
61
|
+
#-------------------------------------------------------------------------------
|
62
|
+
# Documentation
|
63
|
+
|
64
|
+
version = Coral::VERSION
|
65
|
+
doc_title = "coral_core #{version}"
|
66
|
+
|
67
|
+
Rake::RDocTask.new do |rdoc|
|
68
|
+
rdoc.rdoc_dir = 'rdoc'
|
69
|
+
rdoc.title = doc_title
|
70
|
+
rdoc.rdoc_files.include('README*')
|
71
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
72
|
+
end
|
73
|
+
|
74
|
+
#---
|
75
|
+
|
76
|
+
YARD::Rake::YardocTask.new do |ydoc|
|
77
|
+
ydoc.files = [ 'README*', 'lib/**/*.rb' ]
|
78
|
+
ydoc.options = [ "--output-dir yardoc", "--title '#{doc_title}'" ]
|
79
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.24
|
data/coral_core.gemspec
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "coral_core"
|
8
|
+
s.version = "0.2.24"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Adrian Webb"]
|
12
|
+
s.date = "2013-05-20"
|
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
|
+
s.email = "adrian.webb@coraltech.net"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitmodules",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"coral_core.gemspec",
|
29
|
+
"lib/coral_core.rb",
|
30
|
+
"lib/coral_core/command.rb",
|
31
|
+
"lib/coral_core/config.rb",
|
32
|
+
"lib/coral_core/core.rb",
|
33
|
+
"lib/coral_core/event.rb",
|
34
|
+
"lib/coral_core/event/regexp_event.rb",
|
35
|
+
"lib/coral_core/interface.rb",
|
36
|
+
"lib/coral_core/memory.rb",
|
37
|
+
"lib/coral_core/repository.rb",
|
38
|
+
"lib/coral_core/resource.rb",
|
39
|
+
"lib/coral_core/template.rb",
|
40
|
+
"lib/coral_core/template/environment.rb",
|
41
|
+
"lib/coral_core/template/json.rb",
|
42
|
+
"lib/coral_core/template/wrapper.rb",
|
43
|
+
"lib/coral_core/template/yaml.rb",
|
44
|
+
"lib/coral_core/util/data.rb",
|
45
|
+
"lib/coral_core/util/disk.rb",
|
46
|
+
"lib/coral_core/util/git.rb",
|
47
|
+
"lib/coral_core/util/git/base.rb",
|
48
|
+
"lib/coral_core/util/git/lib.rb",
|
49
|
+
"lib/coral_core/util/git/remote.rb",
|
50
|
+
"lib/coral_core/util/shell.rb",
|
51
|
+
"lib/hiera_backend.rb",
|
52
|
+
"spec/coral_core/interface_spec.rb",
|
53
|
+
"spec/coral_mock_input.rb",
|
54
|
+
"spec/coral_test_kernel.rb",
|
55
|
+
"spec/spec_helper.rb"
|
56
|
+
]
|
57
|
+
s.homepage = "http://github.com/coraltech/ruby-coral_core"
|
58
|
+
s.licenses = ["GPLv3"]
|
59
|
+
s.rdoc_options = ["--title", "Coral Core library", "--main", "README.rdoc", "--line-numbers"]
|
60
|
+
s.require_paths = ["lib"]
|
61
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.8.1")
|
62
|
+
s.rubyforge_project = "coral_core"
|
63
|
+
s.rubygems_version = "1.8.15"
|
64
|
+
s.summary = "Provides core data elements and utilities used in other Coral gems"
|
65
|
+
|
66
|
+
if s.respond_to? :specification_version then
|
67
|
+
s.specification_version = 3
|
68
|
+
|
69
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
70
|
+
s.add_runtime_dependency(%q<log4r>, ["~> 1.1"])
|
71
|
+
s.add_runtime_dependency(%q<deep_merge>, ["~> 1.0"])
|
72
|
+
s.add_runtime_dependency(%q<json>, [">= 1.4"])
|
73
|
+
s.add_runtime_dependency(%q<git>, ["= 1.2.5"])
|
74
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.2"])
|
75
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8"])
|
76
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.10"])
|
77
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
78
|
+
s.add_development_dependency(%q<yard>, ["~> 0.8"])
|
79
|
+
else
|
80
|
+
s.add_dependency(%q<log4r>, ["~> 1.1"])
|
81
|
+
s.add_dependency(%q<deep_merge>, ["~> 1.0"])
|
82
|
+
s.add_dependency(%q<json>, [">= 1.4"])
|
83
|
+
s.add_dependency(%q<git>, ["= 1.2.5"])
|
84
|
+
s.add_dependency(%q<bundler>, ["~> 1.2"])
|
85
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8"])
|
86
|
+
s.add_dependency(%q<rspec>, ["~> 2.10"])
|
87
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
88
|
+
s.add_dependency(%q<yard>, ["~> 0.8"])
|
89
|
+
end
|
90
|
+
else
|
91
|
+
s.add_dependency(%q<log4r>, ["~> 1.1"])
|
92
|
+
s.add_dependency(%q<deep_merge>, ["~> 1.0"])
|
93
|
+
s.add_dependency(%q<json>, [">= 1.4"])
|
94
|
+
s.add_dependency(%q<git>, ["= 1.2.5"])
|
95
|
+
s.add_dependency(%q<bundler>, ["~> 1.2"])
|
96
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8"])
|
97
|
+
s.add_dependency(%q<rspec>, ["~> 2.10"])
|
98
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
99
|
+
s.add_dependency(%q<yard>, ["~> 0.8"])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
data/lib/coral_core.rb
ADDED
@@ -0,0 +1,260 @@
|
|
1
|
+
|
2
|
+
#*******************************************************************************
|
3
|
+
# Coral Core Library
|
4
|
+
#
|
5
|
+
# This provides core data elements and utilities used in the Coral gems.
|
6
|
+
#
|
7
|
+
# Author:: Adrian Webb (mailto:adrian.webb@coraltech.net)
|
8
|
+
# License:: GPLv3
|
9
|
+
|
10
|
+
#-------------------------------------------------------------------------------
|
11
|
+
# Global namespace
|
12
|
+
|
13
|
+
module Kernel
|
14
|
+
|
15
|
+
def dbg(data, label = '')
|
16
|
+
require 'pp'
|
17
|
+
|
18
|
+
puts '>>----------------------'
|
19
|
+
unless label.empty?
|
20
|
+
puts label
|
21
|
+
puts '---'
|
22
|
+
end
|
23
|
+
pp data
|
24
|
+
puts '<<'
|
25
|
+
end
|
26
|
+
|
27
|
+
#---
|
28
|
+
|
29
|
+
def locate(command)
|
30
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
31
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
32
|
+
exts.each do |ext|
|
33
|
+
exe = File.join(path, "#{command}#{ext}")
|
34
|
+
return exe if File.executable?(exe)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
#-------------------------------------------------------------------------------
|
42
|
+
# Properties and
|
43
|
+
|
44
|
+
home = File.dirname(__FILE__)
|
45
|
+
dependencies = File.join(home, 'dependency')
|
46
|
+
|
47
|
+
git_location = locate('git')
|
48
|
+
|
49
|
+
#-------------------------------------------------------------------------------
|
50
|
+
|
51
|
+
$:.unshift(home) unless
|
52
|
+
$:.include?(home) || $:.include?(File.expand_path(home))
|
53
|
+
|
54
|
+
#---
|
55
|
+
|
56
|
+
require 'rubygems'
|
57
|
+
|
58
|
+
#---
|
59
|
+
|
60
|
+
begin
|
61
|
+
require 'log4r'
|
62
|
+
|
63
|
+
rescue LoadError
|
64
|
+
log4r_lib = File.join(dependencies, 'log4r', 'lib')
|
65
|
+
|
66
|
+
$:.push(log4r_lib)
|
67
|
+
require File.join(log4r_lib, 'log4r.rb')
|
68
|
+
end
|
69
|
+
|
70
|
+
#---
|
71
|
+
|
72
|
+
begin
|
73
|
+
require 'deep_merge'
|
74
|
+
|
75
|
+
rescue LoadError
|
76
|
+
deep_merge_lib = File.join(dependencies, 'deep_merge', 'lib')
|
77
|
+
|
78
|
+
$:.push(deep_merge_lib)
|
79
|
+
require File.join(deep_merge_lib, 'deep_merge.rb')
|
80
|
+
end
|
81
|
+
|
82
|
+
#---
|
83
|
+
|
84
|
+
begin
|
85
|
+
require 'json'
|
86
|
+
|
87
|
+
rescue LoadError
|
88
|
+
json_lib = File.join(dependencies, 'json', 'lib')
|
89
|
+
|
90
|
+
$:.push(json_lib)
|
91
|
+
require File.join(json_lib, 'json.rb')
|
92
|
+
end
|
93
|
+
|
94
|
+
#---
|
95
|
+
|
96
|
+
if git_location
|
97
|
+
begin
|
98
|
+
require 'git'
|
99
|
+
|
100
|
+
rescue LoadError
|
101
|
+
git_lib = File.join(dependencies, 'git', 'lib')
|
102
|
+
|
103
|
+
$:.push(git_lib)
|
104
|
+
require File.join(git_lib, 'git.rb')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
#---
|
109
|
+
|
110
|
+
# Include pre core utilities (no internal dependencies)
|
111
|
+
[ :data, :disk ].each do |name|
|
112
|
+
require File.join('coral_core', 'util', name.to_s + ".rb")
|
113
|
+
end
|
114
|
+
|
115
|
+
if git_location
|
116
|
+
require File.join('coral_core', 'util', 'git.rb')
|
117
|
+
|
118
|
+
# Include Git overrides
|
119
|
+
Dir.glob(File.join(home, 'coral_core', 'util', 'git', '*.rb')).each do |file|
|
120
|
+
require file
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Include core
|
125
|
+
[ :config, :interface, :core, :resource, :template ].each do |name|
|
126
|
+
require File.join('coral_core', name.to_s + ".rb")
|
127
|
+
end
|
128
|
+
|
129
|
+
# Include post core utilities
|
130
|
+
# ( normally inherit from core and have no reverse dependencies with
|
131
|
+
# core classes )
|
132
|
+
#
|
133
|
+
[ :shell ].each do |name|
|
134
|
+
require File.join('coral_core', 'util', name.to_s + ".rb")
|
135
|
+
end
|
136
|
+
|
137
|
+
# Include data model
|
138
|
+
[ :event, :command ].each do |name|
|
139
|
+
require File.join('coral_core', name.to_s + ".rb")
|
140
|
+
end
|
141
|
+
|
142
|
+
if git_location
|
143
|
+
[ :repository, :memory ].each do |name|
|
144
|
+
require File.join('coral_core', name.to_s + ".rb")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Include specialized events
|
149
|
+
Dir.glob(File.join(home, 'coral_core', 'event', '*.rb')).each do |file|
|
150
|
+
require file
|
151
|
+
end
|
152
|
+
|
153
|
+
# Include bundled templates
|
154
|
+
Dir.glob(File.join(home, 'coral_core', 'template', '*.rb')).each do |file|
|
155
|
+
require file
|
156
|
+
end
|
157
|
+
|
158
|
+
#---
|
159
|
+
|
160
|
+
require 'hiera_backend.rb'
|
161
|
+
|
162
|
+
#*******************************************************************************
|
163
|
+
# Coral Core Library
|
164
|
+
#
|
165
|
+
# This provides core data elements and utilities used in the Coral gems.
|
166
|
+
#
|
167
|
+
# Author:: Adrian Webb (mailto:adrian.webb@coraltech.net)
|
168
|
+
# License:: GPLv3
|
169
|
+
module Coral
|
170
|
+
|
171
|
+
VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
|
172
|
+
|
173
|
+
#---
|
174
|
+
|
175
|
+
@@ui = Coral::Core.ui
|
176
|
+
|
177
|
+
#---
|
178
|
+
|
179
|
+
def self.ui
|
180
|
+
return @@ui
|
181
|
+
end
|
182
|
+
|
183
|
+
#-----------------------------------------------------------------------------
|
184
|
+
# Initialization
|
185
|
+
|
186
|
+
def self.load(base_path)
|
187
|
+
if File.exists?(base_path)
|
188
|
+
Dir.glob(File.join(base_path, '*.rb')).each do |file|
|
189
|
+
require file
|
190
|
+
end
|
191
|
+
Dir.glob(File.join(base_path, 'event', '*.rb')).each do |file|
|
192
|
+
require file
|
193
|
+
end
|
194
|
+
Dir.glob(File.join(base_path, 'template', '*.rb')).each do |file|
|
195
|
+
require file
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
#---
|
201
|
+
|
202
|
+
@@initialized = false
|
203
|
+
|
204
|
+
def self.initialize
|
205
|
+
unless @@initialized
|
206
|
+
Config.set_property('time', Time.now.to_i)
|
207
|
+
|
208
|
+
# Include Coral extensions
|
209
|
+
Puppet::Node::Environment.new.modules.each do |mod|
|
210
|
+
load(File.join(mod.path, 'lib', 'coral'))
|
211
|
+
end
|
212
|
+
|
213
|
+
@@initialized = true
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
#-----------------------------------------------------------------------------
|
218
|
+
# External execution
|
219
|
+
|
220
|
+
def self.run
|
221
|
+
begin
|
222
|
+
initialize
|
223
|
+
yield
|
224
|
+
|
225
|
+
rescue Exception => error
|
226
|
+
ui.warn(error.inspect)
|
227
|
+
ui.warn(Util::Data.to_yaml(error.backtrace))
|
228
|
+
raise
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
#-------------------------------------------------------------------------------
|
234
|
+
# Data type alterations
|
235
|
+
|
236
|
+
class Hash
|
237
|
+
def search(search_key, options = {})
|
238
|
+
config = Coral::Config.ensure(options)
|
239
|
+
value = nil
|
240
|
+
|
241
|
+
recurse = config.get(:recurse, false)
|
242
|
+
recurse_level = config.get(:recurse_level, -1)
|
243
|
+
|
244
|
+
self.each do |key, data|
|
245
|
+
if key == search_key
|
246
|
+
value = data
|
247
|
+
|
248
|
+
elsif data.is_a?(Hash) &&
|
249
|
+
recurse && (recurse_level == -1 || recurse_level > 0)
|
250
|
+
|
251
|
+
recurse_level -= 1 unless recurse_level == -1
|
252
|
+
value = value.search(search_key,
|
253
|
+
Coral::Config.new(config).set(:recurse_level, recurse_level)
|
254
|
+
)
|
255
|
+
end
|
256
|
+
break unless value.nil?
|
257
|
+
end
|
258
|
+
return value
|
259
|
+
end
|
260
|
+
end
|