corl 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -10
- data/Gemfile.lock +13 -11
- data/README.rdoc +1 -1
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/corl +2 -54
- data/bootstrap/bootstrap.sh +91 -0
- data/bootstrap/lib/shell/LICENSE.txt +674 -0
- data/bootstrap/lib/shell/command.sh +214 -0
- data/bootstrap/lib/shell/filesystem.sh +139 -0
- data/bootstrap/lib/shell/load.sh +73 -0
- data/bootstrap/lib/shell/os.sh +67 -0
- data/bootstrap/lib/shell/script.sh +160 -0
- data/bootstrap/lib/shell/starter.sh +64 -0
- data/bootstrap/lib/shell/validators.sh +50 -0
- data/bootstrap/os/ubuntu/00_base.sh +5 -0
- data/bootstrap/os/ubuntu/01_git.sh +5 -0
- data/bootstrap/os/ubuntu/05_ruby.sh +7 -0
- data/bootstrap/os/ubuntu/06_puppet.sh +38 -0
- data/bootstrap/os/ubuntu/10_corl.sh +9 -0
- data/corl.gemspec +61 -124
- data/lib/{corl → CORL}/action/bootstrap.rb +13 -7
- data/lib/CORL/action/exec.rb +39 -0
- data/lib/CORL/action/image.rb +31 -0
- data/lib/{corl → CORL}/action/images.rb +1 -1
- data/lib/CORL/action/lookup.rb +34 -0
- data/lib/{corl → CORL}/action/machines.rb +1 -1
- data/lib/CORL/action/provision.rb +31 -0
- data/lib/{corl → CORL}/action/seed.rb +3 -3
- data/lib/{corl → CORL}/action/spawn.rb +2 -2
- data/lib/CORL/action/start.rb +31 -0
- data/lib/CORL/action/stop.rb +31 -0
- data/lib/{corl → CORL}/configuration/file.rb +1 -1
- data/lib/{corl → CORL}/event/puppet.rb +1 -1
- data/lib/{corl → CORL}/extension/puppetloader.rb +1 -1
- data/lib/{corl → CORL}/machine/fog.rb +3 -3
- data/lib/{corl → CORL}/machine/physical.rb +2 -2
- data/lib/{corl → CORL}/network/default.rb +1 -1
- data/lib/{corl → CORL}/node/aws.rb +0 -4
- data/lib/{corl → CORL}/node/google.rb +0 -4
- data/lib/{corl → CORL}/node/local.rb +1 -1
- data/lib/{corl → CORL}/node/rackspace.rb +0 -4
- data/lib/{corl → CORL}/provisioner/puppetnode.rb +1 -14
- data/lib/{corl → CORL}/provisioner/puppetnode/resource.rb +0 -0
- data/lib/{corl → CORL}/provisioner/puppetnode/resource_group.rb +0 -0
- data/lib/{corl → CORL}/template/environment.rb +1 -1
- data/lib/core/facade.rb +49 -0
- data/lib/{corl_core → core}/mixin/action/keypair.rb +10 -10
- data/lib/{corl_core → core}/mixin/lookup.rb +0 -0
- data/lib/{corl_core → core}/mod/hiera_backend.rb +0 -0
- data/lib/{corl_core/mixin/action/node.rb → core/plugin/action.rb} +66 -33
- data/lib/{corl_core → core}/plugin/configuration.rb +2 -2
- data/lib/{corl/node → core/plugin}/fog.rb +5 -1
- data/lib/{corl_core → core}/plugin/machine.rb +2 -2
- data/lib/{corl_core → core}/plugin/network.rb +4 -4
- data/lib/{corl_core → core}/plugin/node.rb +11 -9
- data/lib/{corl_core → core}/plugin/provisioner.rb +2 -2
- data/lib/{corl_core → core}/util/ssh.rb +1 -1
- data/lib/corl.rb +53 -112
- data/lib/puppet/parser/functions/ensure.rb +0 -4
- data/locales/en.yml +55 -148
- metadata +84 -222
- data/lib/corl/action/add.rb +0 -69
- data/lib/corl/action/clone.rb +0 -40
- data/lib/corl/action/create.rb +0 -55
- data/lib/corl/action/exec.rb +0 -41
- data/lib/corl/action/extract.rb +0 -49
- data/lib/corl/action/image.rb +0 -30
- data/lib/corl/action/lookup.rb +0 -35
- data/lib/corl/action/provision.rb +0 -37
- data/lib/corl/action/remove.rb +0 -51
- data/lib/corl/action/save.rb +0 -53
- data/lib/corl/action/start.rb +0 -37
- data/lib/corl/action/stop.rb +0 -30
- data/lib/corl/action/update.rb +0 -37
- data/lib/corl/command/shell.rb +0 -164
- data/lib/corl/event/regex.rb +0 -52
- data/lib/corl/project/git.rb +0 -465
- data/lib/corl/project/github.rb +0 -108
- data/lib/corl/template/json.rb +0 -16
- data/lib/corl/template/wrapper.rb +0 -16
- data/lib/corl/template/yaml.rb +0 -16
- data/lib/corl/translator/json.rb +0 -27
- data/lib/corl/translator/yaml.rb +0 -27
- data/lib/corl_core/codes.rb +0 -107
- data/lib/corl_core/config.rb +0 -337
- data/lib/corl_core/config/collection.rb +0 -57
- data/lib/corl_core/config/options.rb +0 -70
- data/lib/corl_core/core.rb +0 -59
- data/lib/corl_core/corl.rb +0 -254
- data/lib/corl_core/errors.rb +0 -84
- data/lib/corl_core/facade.rb +0 -126
- data/lib/corl_core/gems.rb +0 -72
- data/lib/corl_core/manager.rb +0 -425
- data/lib/corl_core/mixin/action/commit.rb +0 -58
- data/lib/corl_core/mixin/action/project.rb +0 -53
- data/lib/corl_core/mixin/action/push.rb +0 -52
- data/lib/corl_core/mixin/config/collection.rb +0 -53
- data/lib/corl_core/mixin/config/ops.rb +0 -53
- data/lib/corl_core/mixin/config/options.rb +0 -39
- data/lib/corl_core/mixin/macro/object_interface.rb +0 -361
- data/lib/corl_core/mixin/macro/plugin_interface.rb +0 -380
- data/lib/corl_core/mixin/settings.rb +0 -46
- data/lib/corl_core/mixin/sub_config.rb +0 -148
- data/lib/corl_core/mod/hash.rb +0 -29
- data/lib/corl_core/plugin/action.rb +0 -381
- data/lib/corl_core/plugin/base.rb +0 -374
- data/lib/corl_core/plugin/command.rb +0 -98
- data/lib/corl_core/plugin/event.rb +0 -53
- data/lib/corl_core/plugin/extension.rb +0 -12
- data/lib/corl_core/plugin/project.rb +0 -927
- data/lib/corl_core/plugin/template.rb +0 -80
- data/lib/corl_core/plugin/translator.rb +0 -38
- data/lib/corl_core/util/cli.rb +0 -352
- data/lib/corl_core/util/data.rb +0 -404
- data/lib/corl_core/util/disk.rb +0 -114
- data/lib/corl_core/util/git.rb +0 -47
- data/lib/corl_core/util/interface.rb +0 -319
- data/lib/corl_core/util/liquid.rb +0 -17
- data/lib/corl_core/util/package.rb +0 -93
- data/lib/corl_core/util/shell.rb +0 -239
- data/spec/corl_core/interface_spec.rb +0 -489
@@ -1,58 +0,0 @@
|
|
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
|
-
|
@@ -1,53 +0,0 @@
|
|
1
|
-
|
2
|
-
module CORL
|
3
|
-
module Mixin
|
4
|
-
module Action
|
5
|
-
module Project
|
6
|
-
|
7
|
-
#-----------------------------------------------------------------------------
|
8
|
-
# Options
|
9
|
-
|
10
|
-
def project_options(parser, ref_override = false, rev_override = false)
|
11
|
-
parser.option_str(:project_provider, 'git',
|
12
|
-
'--proj-provider PROVIDER',
|
13
|
-
'corl.core.mixins.project.options.provider'
|
14
|
-
)
|
15
|
-
if ref_override
|
16
|
-
parser.option_str(:reference, nil,
|
17
|
-
'--reference PROJECT_REF',
|
18
|
-
'corl.core.mixins.project.options.reference'
|
19
|
-
)
|
20
|
-
end
|
21
|
-
if rev_override
|
22
|
-
parser.option_str(:revision, nil,
|
23
|
-
'--revision PROJECT_REV',
|
24
|
-
'corl.core.mixins.project.options.revision'
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
#-----------------------------------------------------------------------------
|
30
|
-
# Operations
|
31
|
-
|
32
|
-
def project_load(root_dir, update = false)
|
33
|
-
|
34
|
-
# 1. Set a default project provider (reference can override)
|
35
|
-
# 2. Get project from root directory
|
36
|
-
# 3. Initialize project if not yet initialized
|
37
|
-
# 4. Set remote if needed
|
38
|
-
# 5. Checkout revision if needed
|
39
|
-
# 6. Pull down updates if requested
|
40
|
-
|
41
|
-
return CORL.project(extended_config(:project, {
|
42
|
-
:provider => settings[:project_provider],
|
43
|
-
:directory => root_dir,
|
44
|
-
:url => settings[:reference],
|
45
|
-
:revision => settings[:revision],
|
46
|
-
:pull => update
|
47
|
-
}))
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
@@ -1,52 +0,0 @@
|
|
1
|
-
|
2
|
-
module CORL
|
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
|
-
'corl.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
|
-
'corl.core.mixins.push.options.propogate'
|
23
|
-
)
|
24
|
-
parser.option_str(:remote, :edit,
|
25
|
-
'--remote PROJECT_REMOTE',
|
26
|
-
'corl.core.mixins.push.options.remote'
|
27
|
-
)
|
28
|
-
parser.option_str(:revision, :master,
|
29
|
-
'--revision PROJECT_REVISION',
|
30
|
-
'corl.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
|
-
|
@@ -1,53 +0,0 @@
|
|
1
|
-
|
2
|
-
# Should be included via extend
|
3
|
-
#
|
4
|
-
# extend Mixin::ConfigCollection
|
5
|
-
#
|
6
|
-
|
7
|
-
module CORL
|
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
|
@@ -1,53 +0,0 @@
|
|
1
|
-
|
2
|
-
# Should be included via extend
|
3
|
-
#
|
4
|
-
# extend Mixin::ConfigOps
|
5
|
-
#
|
6
|
-
|
7
|
-
module CORL
|
8
|
-
module Mixin
|
9
|
-
module ConfigOps
|
10
|
-
|
11
|
-
#-----------------------------------------------------------------------------
|
12
|
-
# Parsing
|
13
|
-
|
14
|
-
def parse(statement, options = {})
|
15
|
-
config = Config.ensure(options)
|
16
|
-
|
17
|
-
# statement = common->php::apache::memory_limit = 32M
|
18
|
-
# statement = identity -> test -> users::user[admin][shell]
|
19
|
-
# statement = nodes->development->dev.loc->facts[server_location]
|
20
|
-
# statement = corl->nodes[vagrant][dev.loc][vm][private_network]=172.5.5.10
|
21
|
-
# statement = corl->settings[debug][puppet][options] = ["--debug"]
|
22
|
-
|
23
|
-
reference, new_value = statement.split(/\=/)
|
24
|
-
new_value = new_value.join('=').strip if new_value && new_value.is_a?(Array)
|
25
|
-
|
26
|
-
config_elements = reference.gsub(/\s+/, '').split(/\-\>/)
|
27
|
-
property = config_elements.pop
|
28
|
-
config_file = config_elements.pop
|
29
|
-
|
30
|
-
if config_directory = config.get(:directory, nil)
|
31
|
-
config_path = File.join(project.directory, config_directory, *config_elements)
|
32
|
-
else
|
33
|
-
config_path = File.join(project.directory, *config_elements)
|
34
|
-
end
|
35
|
-
|
36
|
-
return nil unless property && config_file
|
37
|
-
|
38
|
-
config_file = "#{config_file}." + config.get(:ext, 'json')
|
39
|
-
property = property.gsub(/\]$/, '').split(/\]?\[/)
|
40
|
-
data = open(config_path, config_file, config)
|
41
|
-
|
42
|
-
return {
|
43
|
-
:path => config_path,
|
44
|
-
:file => config_file,
|
45
|
-
:property => property,
|
46
|
-
:conf => data,
|
47
|
-
:current_value => (data ? data.get(property) : nil),
|
48
|
-
:new_value => eval(new_value)
|
49
|
-
}
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
|
2
|
-
# Should be included via extend
|
3
|
-
#
|
4
|
-
# extend Mixin::ConfigOptions
|
5
|
-
#
|
6
|
-
|
7
|
-
module CORL
|
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
|
@@ -1,361 +0,0 @@
|
|
1
|
-
|
2
|
-
# Should be included via extend
|
3
|
-
#
|
4
|
-
# extend Mixin::Macro::ObjectInterface
|
5
|
-
#
|
6
|
-
|
7
|
-
module CORL
|
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
|