Module: PoolParty::Resources
- Included in:
- Cloud::Cloud, Plugin::Plugin, Plugin::Plugin, Resource, Resource
- Defined in:
- lib/poolparty/pool/resource.rb,
lib/poolparty/pool/resources/gem.rb,
lib/poolparty/pool/resources/cron.rb,
lib/poolparty/pool/resources/exec.rb,
lib/poolparty/pool/resources/file.rb,
lib/poolparty/pool/resources/host.rb,
lib/poolparty/pool/custom_resource.rb,
lib/poolparty/pool/resources/sshkey.rb,
lib/poolparty/pool/resources/package.rb,
lib/poolparty/pool/resources/service.rb,
lib/poolparty/pool/resources/variable.rb,
lib/poolparty/pool/resources/directory.rb,
lib/poolparty/pool/resources/remote_file.rb,
lib/poolparty/pool/resources/class_package.rb
Defined Under Namespace
Classes: CallFunction, Classpackage, Cron, CustomResource, Directory, Exec, File, Host, Package, Remotefile, Resource, Service, Sshkey, Variable
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_resource(type, opts = {}, &block) ⇒ Object
-
#call_function(str, opts = {}, &block) ⇒ Object
-
#classpackage_with_self(parent = self, &block) ⇒ Object
Wrap all the resources into a class package from.
-
#custom_file(path, str) ⇒ Object
-
#custom_function(*args, &block) ⇒ Object
Stub methods TODO: Find a better solution.
-
#gem(opts = {}, &block) ⇒ Object
-
#get_resource(type, name) ⇒ Object
-
#reset_resources! ⇒ Object
-
#resource(type = :file) ⇒ Object
-
#resources ⇒ Object
-
#resources_string(prev = "") ⇒ Object
-
#resources_string_from_resources(resources, prev = "\t") ⇒ Object
Class Method Details
.add_has_and_does_not_have_methods_for(type = :file) ⇒ Object
Adds two methods to the module
Adds the method type:
has_
and
does_not_have_
for the type passed
for instance
add_has_and_does_not_have_methods_for(:file)
gives you the methods has_file and does_not_have_file
TODO: Refactor nicely to include other types that don't accept ensure
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/poolparty/pool/resource.rb', line 223
def self.add_has_and_does_not_have_methods_for(type=:file)
module_eval <<-EOE
def has_#{type}(opts={}, &block)
#{type}(#{type == :exec ? "opts" : "{:is_present => ''}.merge(opts)"}, &block)
end
def does_not_have_#{type}(opts={}, &block)
#{type}(#{type == :exec ? "opts" : "{:is_absent => ''}.merge(opts)"}, &block)
end
EOE
end
|
.custom_function(*args, &block) ⇒ Object
57
58
|
# File 'lib/poolparty/pool/custom_resource.rb', line 57
def self.custom_function(*args, &block)
end
|
Instance Method Details
#add_resource(type, opts = {}, &block) ⇒ Object
20
21
22
23
24
|
# File 'lib/poolparty/pool/resource.rb', line 20
def add_resource(type, opts={}, &block)
returning "PoolParty::Resources::#{type.to_s.camelize}".classify.constantize.new(opts, &block) do |o|
resource(type) << o
end
end
|
#call_function(str, opts = {}, &block) ⇒ Object
15
16
17
18
19
|
# File 'lib/poolparty/pool/custom_resource.rb', line 15
def call_function(str, opts={}, &block)
returning PoolParty::Resources::CallFunction.new(str, opts, &block) do |o|
resource(:call_function) << o
end
end
|
#classpackage_with_self(parent = self, &block) ⇒ Object
Wrap all the resources into a class package from
5
6
7
8
9
10
|
# File 'lib/poolparty/pool/resources/class_package.rb', line 5
def classpackage_with_self(parent=self, &block)
@cp = PoolParty::Resources::Classpackage.new(parent.options, parent, &block)
@cp.instance_eval {@resources = parent.resources}
parent.instance_eval {@resources = nil}
@cp
end
|
#custom_file(path, str) ⇒ Object
41
42
43
|
# File 'lib/poolparty/pool/resource.rb', line 41
def custom_file(path, str)
write_to_file_in_storage_directory(path, str)
end
|
#custom_function(*args, &block) ⇒ Object
Stub methods
TODO: Find a better solution
55
56
|
# File 'lib/poolparty/pool/custom_resource.rb', line 55
def custom_function(*args, &block)
end
|
#gem(opts = {}, &block) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/poolparty/pool/resources/gem.rb', line 4
def gem(opts={}, &block)
add_resource(:package, opts.merge({
:provider => "gem",
:requires => "Package[rubygems]"
}), &block)
end
|
#get_resource(type, name) ⇒ Object
26
27
28
|
# File 'lib/poolparty/pool/resource.rb', line 26
def get_resource(type, name)
resource(type).select {|resource| resource.name == name }.first
end
|
#reset_resources! ⇒ Object
31
32
33
|
# File 'lib/poolparty/pool/resource.rb', line 31
def reset_resources!
@resources = nil
end
|
#resource(type = :file) ⇒ Object
16
17
18
|
# File 'lib/poolparty/pool/resource.rb', line 16
def resource(type=:file)
resources[type] ||= []
end
|
#resources ⇒ Object
12
13
14
|
# File 'lib/poolparty/pool/resource.rb', line 12
def resources
@resources ||= {}
end
|
#resources_string(prev = "") ⇒ Object
35
36
37
38
39
|
# File 'lib/poolparty/pool/resource.rb', line 35
def resources_string(prev="")
returning Array.new do |output|
output << resources_string_from_resources(resources)
end.join("\n")
end
|
#resources_string_from_resources(resources, prev = "\t") ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/poolparty/pool/resources/class_package.rb', line 42
def resources_string_from_resources(resources, prev="\t")
@variables = resources. {|name,resource| name == :variable}
returning Array.new do |str|
unless @variables.empty?
str << "\n# Variables \n"
@variables.each do |name, variable|
str << variable.to_string("#{prev}")
end
end
resources.each do |type, resource|
str << "\n#{prev*2}# #{type}\n"
str << resource.to_string("#{prev*2}")
end
end.join("\n")
end
|