Module: CfFactory::CfBase
- Included in:
- CfAsGroup, CfAsLaunchConfig, CfAsScalingPolicy, CfAttachGateway, CfCloudWatchAlarm, CfCloudfrontDistribution, CfDynamoTable, CfEbApplication, CfEbEnvironment, CfEbsVolume, CfEc2Instance, CfEc2SecurityGroup, CfEip, CfEipAssociation, CfElb, CfIamAccessKey, CfIamGroup, CfIamInstanceProfile, CfIamRole, CfIamUser, CfInternetGateway, CfNetworkAcl, CfNetworkAclAssociation, CfNetworkAclEntry, CfNetworkInterface, CfOutput, CfParameter, CfRdsInstance, CfRdsSecurityGroup, CfRdsSubnetGroup, CfRoute, CfRoute53RecordSet, CfRoute53RecordSetGroup, CfRouteTable, CfRouteTableAssociation, CfS3Bucket, CfSqsQueue, CfSubnet, CfVpc
- Defined in:
- lib/cf_factory/base/cf_base.rb
Instance Method Summary collapse
- #generate ⇒ Object
- #generate_ref ⇒ Object
- #get_cf_attributes ⇒ Object
- #get_cf_properties ⇒ Object
- #get_cf_type ⇒ Object
- #get_deletion_policy ⇒ Object
- #get_name ⇒ Object
- #get_update_policy ⇒ Object
- #hash_to_string(hash, indent = 0) ⇒ Object
- #retrieve_attribute(attribute) ⇒ Object
- #set_meta_data(meta_data) ⇒ Object
-
#set_quotes(value) ⇒ Object
Sets leading and trailing quotes.
- #set_tags(tag_list) ⇒ Object
Instance Method Details
#generate ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cf_factory/base/cf_base.rb', line 66 def generate @result = "" @result += " \"#{@name}\" : {\n" unless self.get_cf_type() == nil @result += " \"Type\" : \"#{self.get_cf_type()}\",\n" end unless self.get_deletion_policy() == nil @result += " \"DeletionPolicy\" : \"#{self.get_deletion_policy()}\",\n" end unless self.get_update_policy() == nil self.get_update_policy.set_indent(8) @result += " \"UpdatePolicy\" : {\n" @result += "#{self.get_update_policy.generate()}\n" @result += " },\n" end attributes = self.get_cf_attributes unless attributes.size == 0 @result += "#{hash_to_string(attributes)},\n" end # properties = self.get_cf_properties properties["Tags"] = CfHelper.generate_inner_array(@tag_list) unless @tag_list.nil? unless properties.size == 0 @result += " \"Properties\" : {\n" @result += hash_to_string(properties) @result += "\n }" end @result = @result.chomp.chomp(",") @result += "\n },\n" end |
#generate_ref ⇒ Object
31 32 33 |
# File 'lib/cf_factory/base/cf_base.rb', line 31 def generate_ref CfHelper.generate_ref(self.get_name) end |
#get_cf_attributes ⇒ Object
21 22 23 24 25 |
# File 'lib/cf_factory/base/cf_base.rb', line 21 def get_cf_attributes result = {} result["Metadata"] = @meta_data.generate unless @meta_data.nil? result end |
#get_cf_properties ⇒ Object
27 28 29 |
# File 'lib/cf_factory/base/cf_base.rb', line 27 def get_cf_properties raise Exception.new("must be defined") end |
#get_cf_type ⇒ Object
9 10 11 |
# File 'lib/cf_factory/base/cf_base.rb', line 9 def get_cf_type raise Exception.new("must be defined") end |
#get_deletion_policy ⇒ Object
13 14 15 |
# File 'lib/cf_factory/base/cf_base.rb', line 13 def get_deletion_policy @deletion_policy end |
#get_name ⇒ Object
5 6 7 |
# File 'lib/cf_factory/base/cf_base.rb', line 5 def get_name @name end |
#get_update_policy ⇒ Object
17 18 19 |
# File 'lib/cf_factory/base/cf_base.rb', line 17 def get_update_policy @update_policy end |
#hash_to_string(hash, indent = 0) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cf_factory/base/cf_base.rb', line 47 def hash_to_string(hash, indent=0) output = "" hash.keys.each() do |key| value = hash[key] output += " " * indent case value.class.to_s when "Hash" output += " \"#{key}\" : \n{#{hash_to_string(value,indent+5)}},\n" when "EmbeddedProperty" output += " \"#{key}\" : \n{#{hash_to_string(value.generate,indent+5)},\n" else output += " \"#{key}\" : #{set_quotes(value)},\n" end end output output = output.chomp().chomp(",") end |
#retrieve_attribute(attribute) ⇒ Object
35 36 37 |
# File 'lib/cf_factory/base/cf_base.rb', line 35 def retrieve_attribute(attribute) CfHelper.generate_att(@name, attribute) end |
#set_meta_data(meta_data) ⇒ Object
39 40 41 |
# File 'lib/cf_factory/base/cf_base.rb', line 39 def () @meta_data = end |
#set_quotes(value) ⇒ Object
Sets leading and trailing quotes
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/cf_factory/base/cf_base.rb', line 98 def set_quotes(value) if value.class.to_s == "String" if value.delete(" ").start_with?("{") || value.delete(" ").start_with?("[") value else "\"#{value}\"" end else value end end |
#set_tags(tag_list) ⇒ Object
43 44 45 |
# File 'lib/cf_factory/base/cf_base.rb', line 43 def (tag_list) #should be overwritten by those resources that support tags end |