Class: PoolParty::Schema
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(h = {}) ⇒ Schema
Returns a new instance of Schema.
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/poolparty/schema.rb', line 9
def initialize(h={})
@hsh = {}
case h
when Hash
h.each {|k,v| self[k] = v}
when Array
h.each {|el| self[el['ip']]=el}
when String
JSON.parse(h).each {|k,v| self[k.to_sym] = v}
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/poolparty/schema.rb', line 41
def method_missing(sym, *args, &block)
if @hsh.has_key?(sym.to_sym)
@hsh.fetch(sym)
elsif @hsh.has_key?(sym.to_s)
@hsh.fetch(sym.to_s)
else
@hsh.send(sym, *args, &block)
end
end
|
Instance Attribute Details
Returns the value of attribute hsh.
8
9
10
|
# File 'lib/poolparty/schema.rb', line 8
def hsh
@hsh
end
|
Instance Method Details
21
22
23
|
# File 'lib/poolparty/schema.rb', line 21
def [](k)
hsh[k]
end
|
#[]=(k, v) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/poolparty/schema.rb', line 25
def []=(k,v)
if v.is_a?(Hash)
hsh[k.to_sym] = self.class.new(v)
else
hsh[k.to_sym] = v
end
end
|
37
38
39
|
# File 'lib/poolparty/schema.rb', line 37
def save!
::File.open("#{Default.base_config_directory}/#{Default.properties_hash_filename}", "w") {|f| f << self.to_json }
end
|
#to_cloud(node = {}) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/poolparty/schema.rb', line 51
def to_cloud(node={})
require "ostruct"
$pool_specfile = "/etc/poolparty/clouds.rb"
remoter_base = PoolParty::Remote.module_eval(options.remote_base.split('::')[-1].camelcase)
cld = OpenStruct.new(options)
cld.keypair = ::PoolParty::Key.new("/etc/poolparty/#{node[:keypair]}")
cld.remoter_base = remoter_base
cld.build_and_store_new_config_file = "/etc/poolparty/clouds.json"
cld.dependency_resolver = PoolParty.module_eval(options.dependency_resolver.split("::")[-1].camelcase).send(:new)
cld
end
|
33
34
35
|
# File 'lib/poolparty/schema.rb', line 33
def to_hash
@hsh
end
|