Module: CfBase
- Included in:
- CfAsGroup, CfAsLaunchConfig, CfAsScalingPolicy, CfAttachGateway, CfCloudWatchAlarm, CfCloudfrontDistribution, 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cf_factory/base/cf_base.rb', line 59 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
26 27 28 |
# File 'lib/cf_factory/base/cf_base.rb', line 26 def generate_ref CfHelper.generate_ref(self.get_name) end |
#get_cf_attributes ⇒ Object
16 17 18 19 20 |
# File 'lib/cf_factory/base/cf_base.rb', line 16 def get_cf_attributes result = {} result["Metadata"] = @meta_data.generate unless @meta_data.nil? result end |
#get_cf_properties ⇒ Object
22 23 24 |
# File 'lib/cf_factory/base/cf_base.rb', line 22 def get_cf_properties raise Exception.new("must be defined") end |
#get_cf_type ⇒ Object
8 9 10 |
# File 'lib/cf_factory/base/cf_base.rb', line 8 def get_cf_type raise Exception.new("must be defined") end |
#get_deletion_policy ⇒ Object
12 13 14 |
# File 'lib/cf_factory/base/cf_base.rb', line 12 def get_deletion_policy @deletion_policy end |
#get_name ⇒ Object
4 5 6 |
# File 'lib/cf_factory/base/cf_base.rb', line 4 def get_name @name end |
#hash_to_string(hash, indent = 0) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cf_factory/base/cf_base.rb', line 42 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" else output += " \"#{key}\" : #{set_quotes(value)},\n" end end output output = output.chomp().chomp(",") end |
#retrieve_attribute(attribute) ⇒ Object
30 31 32 |
# File 'lib/cf_factory/base/cf_base.rb', line 30 def retrieve_attribute(attribute) CfHelper.generate_att(@name, attribute) end |
#set_meta_data(meta_data) ⇒ Object
34 35 36 |
# File 'lib/cf_factory/base/cf_base.rb', line 34 def () @meta_data = end |
#set_quotes(value) ⇒ Object
Sets leading and trailing quotes
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cf_factory/base/cf_base.rb', line 85 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
38 39 40 |
# File 'lib/cf_factory/base/cf_base.rb', line 38 def (tag_list) #should be overwritten by those resources that support tags end |