Class: CloudBuilder::Resource
- Inherits:
-
Object
- Object
- CloudBuilder::Resource
show all
- Includes:
- ExposesRefs
- Defined in:
- lib/cloud_builder/resource.rb
Instance Method Summary
collapse
#base64, #get_att, #join, #ref
Constructor Details
#initialize(stack, name, &block) ⇒ Resource
Returns a new instance of Resource.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/cloud_builder/resource.rb', line 6
def initialize(stack, name, &block)
@stack = stack
@type = nil
@properties = {}
@metadata = {}
@block = block
@deletion_policy = nil
@update_policy = nil
@depends_on = nil
if @block.binding.eval('@type')
metadata do
brick_name @block.binding.eval('@type')
end
end
instance_eval(&block)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(field, *params) ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/cloud_builder/resource.rb', line 102
def method_missing(field, *params)
if @stack.reference_type(field.to_s) == :map
Reference::Map.new(field)
else
@current_map[DSL.format(field)] = DSL.jsonize(params.first)
end
end
|
Instance Method Details
#brick ⇒ Object
60
61
62
|
# File 'lib/cloud_builder/resource.rb', line 60
def brick
@block.binding.eval('brick')
end
|
#deletion_policy(value) ⇒ Object
48
49
50
|
# File 'lib/cloud_builder/resource.rb', line 48
def deletion_policy(value)
@deletion_policy = value
end
|
#depends_on(value) ⇒ Object
52
53
54
|
# File 'lib/cloud_builder/resource.rb', line 52
def depends_on(value)
@depends_on = value
end
|
#globals ⇒ Object
64
65
66
|
# File 'lib/cloud_builder/resource.rb', line 64
def globals
@stack.globals
end
|
41
42
43
44
45
46
|
# File 'lib/cloud_builder/resource.rb', line 41
def metadata
old_map = @current_map
@current_map = @metadata
yield
@current_map = old_map
end
|
#properties ⇒ Object
34
35
36
37
38
39
|
# File 'lib/cloud_builder/resource.rb', line 34
def properties
old_map = @current_map
@current_map = @properties
yield
@current_map = old_map
end
|
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/cloud_builder/resource.rb', line 68
def tags(tag_map, propagate = nil)
list = @current_map[TAGS] ||= []
tag_map = Hash[tag_map.map { |key, value| [key.to_s, value] }]
tag_map.keys.sort.each do |key|
if propagate.nil?
list << {KEY => DSL.format(key), VALUE => DSL.jsonize(tag_map[key])}
else
list << {KEY => DSL.format(key), VALUE => DSL.jsonize(tag_map[key]), PROPAGATE_AT_LAUNCH => propagate }
end
end
end
|
#to_json_data ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/cloud_builder/resource.rb', line 80
def to_json_data
ret = {TYPE => @type, METADATA => @metadata, PROPERTIES => @properties}
if @version
ret["Version"] = @version
end
if @deletion_policy
ret[DELETION_POLICY] = @deletion_policy
end
if @depends_on
ret[DEPENDS_ON] = @depends_on
end
if @update_policy
ret[UPDATE_POLICY] = @update_policy
end
ret
end
|
#type(value) ⇒ Object
26
27
28
|
# File 'lib/cloud_builder/resource.rb', line 26
def type(value)
@type = value
end
|
#update_policy(value) ⇒ Object
56
57
58
|
# File 'lib/cloud_builder/resource.rb', line 56
def update_policy(value)
@update_policy = value
end
|
#version(value) ⇒ Object
30
31
32
|
# File 'lib/cloud_builder/resource.rb', line 30
def version(value)
@version = value
end
|