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, 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
- #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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cf_factory/base/cf_base.rb', line 62 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 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
27 28 29 |
# File 'lib/cf_factory/base/cf_base.rb', line 27 def generate_ref CfHelper.generate_ref(self.get_name) end |
#get_cf_attributes ⇒ Object
17 18 19 20 21 |
# File 'lib/cf_factory/base/cf_base.rb', line 17 def get_cf_attributes result = {} result["Metadata"] = @meta_data.generate unless @meta_data.nil? result end |
#get_cf_properties ⇒ Object
23 24 25 |
# File 'lib/cf_factory/base/cf_base.rb', line 23 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 |
#hash_to_string(hash, indent = 0) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cf_factory/base/cf_base.rb', line 43 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
31 32 33 |
# File 'lib/cf_factory/base/cf_base.rb', line 31 def retrieve_attribute(attribute) CfHelper.generate_att(@name, attribute) end |
#set_meta_data(meta_data) ⇒ Object
35 36 37 |
# File 'lib/cf_factory/base/cf_base.rb', line 35 def () @meta_data = end |
#set_quotes(value) ⇒ Object
Sets leading and trailing quotes
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cf_factory/base/cf_base.rb', line 88 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
39 40 41 |
# File 'lib/cf_factory/base/cf_base.rb', line 39 def (tag_list) #should be overwritten by those resources that support tags end |