Module: CloudFormer::MakesJson

Included in:
MetadataResource, Parameter, Resource, ResourceProperty
Defined in:
lib/cloud_former/makes_json.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


8
9
10
11
12
# File 'lib/cloud_former/makes_json.rb', line 8

def self.included(base)
  base.extend ClassMethods
  base.class_variable_set('@@json_attributes', [])
  base.class_variable_set('@@embed_properties', false)
end

Instance Method Details

#dump_jsonObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cloud_former/makes_json.rb', line 14

def dump_json
  res = {}
  self.class.class_variable_get('@@json_attributes').each do |att|
    use_name = att[:options][:name] || ActiveSupport::Inflector.camelize(att[:name])
    res[use_name] = self.send(att[:name])
  end

  properties = {}

  self.class.aws_properties.try(:each) do |property|
    val = property.as_json_for(self)
    if !val.nil?
      use_name = property.options[:name]
      use_name ||= ActiveSupport::Inflector.camelize(property.get_name)
      properties[use_name] = val
    end
  end

  attribute_fill = res
  if self.class.get_aws_attribute_wrapper
    attribute_fill = {}
  end

  self.class.aws_attributes.try(:each) do |attribute|
    val = attribute.as_json_for(self)
    if !val.nil?
      use_name = attribute.options[:name]
      use_name ||= ActiveSupport::Inflector.camelize(attribute.get_name)
      attribute_fill[use_name] = val
    end
  end

  if self.class.get_aws_attribute_wrapper
    res[self.class.get_aws_attribute_wrapper] = attribute_fill
  end

  if properties.any?
    res['Properties'] = properties
  end

  if respond_to?('metadata_items') && .any?
     = {}
    .each do |meta|
      [meta.aws_type] = meta.dump_json
    end
    res['Metadata'] = 
  end

  res
end