Class: Momo::Resource
- Includes:
- MomoCondition
- Defined in:
- lib/momo/resource.rb
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#deletion_policy ⇒ Object
Returns the value of attribute deletion_policy.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
-
#props ⇒ Object
Returns the value of attribute props.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_thing(group, name, thing) ⇒ Object
- #complete! ⇒ Object
- #depends_on(resource) ⇒ Object
- #file(name, options = {}) ⇒ Object
- #gem(package) ⇒ Object
- #init_cfinit! ⇒ Object
- #init_group(group) ⇒ Object
- #init_metadata! ⇒ Object
-
#initialize(type, name, stack) ⇒ Resource
constructor
A new instance of Resource.
- #method_missing(name, *args, &block) ⇒ Object
- #rpm(package) ⇒ Object
- #service(service_name) ⇒ Object
- #set_deletion_policy(value) ⇒ Object
- #set_thing(group, subgroup, name, thing) ⇒ Object
- #set_thing2(group, name, thing) ⇒ Object
- #tag(key, value, options = {}) ⇒ Object
- #yum(package) ⇒ Object
Methods included from MomoCondition
Methods inherited from MomoScope
Constructor Details
#initialize(type, name, stack) ⇒ Resource
Returns a new instance of Resource.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/momo/resource.rb', line 9 def initialize(type, name, stack) @type = type @name = name @metadata = nil @props = {} @condition = nil @dependencies = [] @complete = false @deletion_policy = nil @stack = stack end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/momo/resource.rb', line 21 def method_missing(name, *args, &block) if !@complete if /^[[:upper:]]/.match(name) == nil raise "Invalid property name: #{name}" end @props[name] = Momo.resolve(args[0], resource: name, stack: @stack, &block) else if /^[[:upper:]]/.match(name) == nil raise "Invalid attribute name: #{name}" end # For get attributes when the resource is completed # TODO: should instead instance eval with a different class MemberReference.new @name, name, @stack end end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
7 8 9 |
# File 'lib/momo/resource.rb', line 7 def condition @condition end |
#deletion_policy ⇒ Object
Returns the value of attribute deletion_policy.
7 8 9 |
# File 'lib/momo/resource.rb', line 7 def deletion_policy @deletion_policy end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
7 8 9 |
# File 'lib/momo/resource.rb', line 7 def dependencies @dependencies end |
#metadata ⇒ Object
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/momo/resource.rb', line 7 def @metadata end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/momo/resource.rb', line 7 def name @name end |
#props ⇒ Object
Returns the value of attribute props.
7 8 9 |
# File 'lib/momo/resource.rb', line 7 def props @props end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/momo/resource.rb', line 7 def type @type end |
Instance Method Details
#add_thing(group, name, thing) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/momo/resource.rb', line 81 def add_thing(group, name, thing) init_group(group) if !@metadata["AWS::CloudFormation::Init"]["config"][group][name] @metadata["AWS::CloudFormation::Init"]["config"][group][name] = [] end @metadata["AWS::CloudFormation::Init"]["config"][group][name] << thing end |
#complete! ⇒ Object
43 44 45 |
# File 'lib/momo/resource.rb', line 43 def complete! @complete = true end |
#depends_on(resource) ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/momo/resource.rb', line 159 def depends_on(resource) if resource.is_a? String @dependencies << args[0] elsif resource.is_a? Resource @dependencies << resource.name else raise "Invalid argument to depends_on: #{resource[0]}" end end |
#file(name, options = {}) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/momo/resource.rb', line 120 def file(name, ={}) info = { "content" => "", "group" => "root", "owner" => "root", "mode" => "000600", "context" => {}, } if [:content] and [:source] raise "Momo CFL Resource: Please specify only file content or source and not both" end info["content"] = [:content] if [:content] info["source"] = [:source] if [:source] info["group"] = [:group] if [:group] info["mode"] = [:mode] if [:mode] info["owner"] = [:owner] if [:owner] info["context"] = Momo.resolve([:context], stack: @stack, resource: name) if [:context] set_thing2("files", name, info) end |
#gem(package) ⇒ Object
112 113 114 |
# File 'lib/momo/resource.rb', line 112 def gem(package) set_thing("packages", "rubygems", package, []) end |
#init_cfinit! ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/momo/resource.rb', line 54 def init_cfinit! if !@metadata["AWS::CloudFormation::Init"] @metadata["AWS::CloudFormation::Init"] = {} end if !@metadata["AWS::CloudFormation::Init"]["config"] @metadata["AWS::CloudFormation::Init"]["config"] = { "packages" => {}, "groups" => {}, "users" => {}, "sources" => {}, "files" => {}, "commands" => {}, "services" => {} } end end |
#init_group(group) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/momo/resource.rb', line 74 def init_group(group) init_cfinit! if !@metadata["AWS::CloudFormation::Init"]["config"][group] @metadata["AWS::CloudFormation::Init"]["config"][group] = {} end end |
#init_metadata! ⇒ Object
47 48 49 50 51 52 |
# File 'lib/momo/resource.rb', line 47 def if !@metadata @metadata = {} end end |
#rpm(package) ⇒ Object
116 117 118 |
# File 'lib/momo/resource.rb', line 116 def rpm(package) set_thing("packages", "rpm", package, []) end |
#service(service_name) ⇒ Object
143 144 145 |
# File 'lib/momo/resource.rb', line 143 def service(service_name) set_thing("services", "sysvinit", service_name, {enabled: true, ensureRunning: true}) end |
#set_deletion_policy(value) ⇒ Object
39 40 41 |
# File 'lib/momo/resource.rb', line 39 def set_deletion_policy(value) @deletion_policy = value end |
#set_thing(group, subgroup, name, thing) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/momo/resource.rb', line 92 def set_thing(group, subgroup, name, thing) init_group(group) if !@metadata["AWS::CloudFormation::Init"]["config"][group][subgroup] @metadata["AWS::CloudFormation::Init"]["config"][group][subgroup] = {} end @metadata["AWS::CloudFormation::Init"]["config"][group][subgroup][name] = thing end |
#set_thing2(group, name, thing) ⇒ Object
102 103 104 105 106 |
# File 'lib/momo/resource.rb', line 102 def set_thing2(group, name, thing) init_group(group) @metadata["AWS::CloudFormation::Init"]["config"][group][name] = thing end |
#tag(key, value, options = {}) ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/momo/resource.rb', line 148 def tag(key, value, ={}) if !@props["Tags"] @props["Tags"] = [] end theTag = { "Key" => key, "Value" => Momo.resolve(value) } theTag["PropagateAtLaunch"] = [:propagate_at_launch] if [:propagate_at_launch] @props["Tags"] << theTag end |
#yum(package) ⇒ Object
108 109 110 |
# File 'lib/momo/resource.rb', line 108 def yum(package) set_thing("packages", "yum", package, []) end |