Class: AwsProvisioner::Properties
- Inherits:
-
Object
- Object
- AwsProvisioner::Properties
show all
- Defined in:
- lib/aws_provisioner/properties.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash = {}) ⇒ Properties
Returns a new instance of Properties.
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/aws_provisioner/properties.rb', line 5
def initialize(hash={})
@properties = hash.reduce({}) do |acc, entry|
key, value = entry
if value.instance_of?(Hash)
acc[key] = Properties.new(value)
else
acc[key] = value
end
acc
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/aws_provisioner/properties.rb', line 75
def method_missing(m, *args, &block)
if @properties.include? m
return @properties[m]
elsif assignment?(m, args, block)
return assign(m, args, block)
else
property = Properties.new
@properties[m] = property
return property
end
end
|
Instance Attribute Details
#properties ⇒ Object
Returns the value of attribute properties.
3
4
5
|
# File 'lib/aws_provisioner/properties.rb', line 3
def properties
@properties
end
|
Instance Method Details
#empty? ⇒ Boolean
19
20
21
|
# File 'lib/aws_provisioner/properties.rb', line 19
def empty?
@properties.empty?
end
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/aws_provisioner/properties.rb', line 44
def reformat_keys
@properties.reduce({}) do |acc, entry|
key, value = entry
if value.instance_of? self.class
acc[key.to_s] = value.reformat_keys
else
acc[key.to_s] = value
end
acc
end
end
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/aws_provisioner/properties.rb', line 23
def rename
renamed_properties = @properties.reduce({}) do |acc, entry|
key, value = entry
template_key = template_name(key)
if value.instance_of? self.class
acc[template_key] = value.rename
else
acc[template_key] = value
end
acc
end
Properties.new(renamed_properties)
end
|
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/aws_provisioner/properties.rb', line 59
def to_h
@properties.reduce({}) do |acc, property|
key, value = property
if value.instance_of? self.class
acc[key] = value.to_h
else
acc[key] = value
end
acc
end
end
|
40
41
42
|
# File 'lib/aws_provisioner/properties.rb', line 40
def to_t
self.rename.reformat_keys.to_h
end
|