Module: CfBase

Instance Method Summary collapse

Instance Method Details

#generateObject



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_refObject



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_attributesObject



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_propertiesObject

Raises:

  • (Exception)


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_typeObject

Raises:

  • (Exception)


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_policyObject



12
13
14
# File 'lib/cf_factory/base/cf_base.rb', line 12

def get_deletion_policy
  @deletion_policy
end

#get_nameObject



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 set_tags(tag_list)
  #should be overwritten by those resources that support tags 
end