Class: Pangea::ModCache

Inherits:
Object
  • Object
show all
Defined in:
lib/pangea/modcache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, mod, resource, virtual) ⇒ ModCache



15
16
17
18
19
20
21
22
23
24
# File 'lib/pangea/modcache.rb', line 15

def initialize(name, mod, resource, virtual)
  @name     = name
  @mod      = mod
  @resource = resource
  @virtual  = virtual
  @basedir = File.join(Dir.home, '.pangea')
  @modcachedir = File.join(basedir, 'modcache')
  @address = "#{name}/#{mod}/#{resource}/#{virtual}/module"
  @internal_module_file_name = 'internal.tf.json'
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



7
8
9
# File 'lib/pangea/modcache.rb', line 7

def address
  @address
end

#basedirObject (readonly)

Returns the value of attribute basedir.



7
8
9
# File 'lib/pangea/modcache.rb', line 7

def basedir
  @basedir
end

#modObject (readonly)

Returns the value of attribute mod.



7
8
9
# File 'lib/pangea/modcache.rb', line 7

def mod
  @mod
end

#modcachedirObject (readonly)

Returns the value of attribute modcachedir.



7
8
9
# File 'lib/pangea/modcache.rb', line 7

def modcachedir
  @modcachedir
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/pangea/modcache.rb', line 7

def name
  @name
end

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/pangea/modcache.rb', line 7

def resource
  @resource
end

#virtualObject (readonly)

Returns the value of attribute virtual.



7
8
9
# File 'lib/pangea/modcache.rb', line 7

def virtual
  @virtual
end

Instance Method Details

#place_caller_templateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pangea/modcache.rb', line 41

def place_caller_template
  internal_module_path = File.join(
    modcachedir,
    @internal_module_file_name
  )
  caller_template = {
    provider: {
      aws: {
        region: 'us-east-1'
      }
    },
    module: {
      "#{name}": {
        source: internal_module_path
      }
    }
  }

  internal_caller_template_path = File.join(
    modcachedir,
    'caller.tf.json'
  )
  File.write(internal_caller_template_path, JSON[caller_template])
end

#place_internal_module(template) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/pangea/modcache.rb', line 32

def place_internal_module(template)
  preflight
  internal_module_path = File.join(
    modcachedir,
    @internal_module_file_name
  )
  File.write(internal_module_path, template)
end

#preflightObject



26
27
28
29
30
# File 'lib/pangea/modcache.rb', line 26

def preflight
  [basedir, modcachedir, File.join(modcachedir, address)].each do |d|
    `mkdir -p #{modcachedir}` unless Dir.exist?(d)
  end
end