Class: Minfra::Cli::StackM::AppTemplate

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/minfra/cli/commands/stack/app_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #deprecated, #error, #exit_error, #info, #warn

Constructor Details

#initialize(name, config) ⇒ AppTemplate

Returns a new instance of AppTemplate.



13
14
15
16
17
18
19
20
21
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 13

def initialize(name, config)
  @name       = name
  @path       = config.stacks_path.join(name)
  @app_path   = @path.join('fxnet-app.json')
  @errors     = []
  @config     = config
  @env        = config.orch_env
  @content    = {}
end

Instance Attribute Details

#app_pathObject (readonly)

Returns the value of attribute app_path.



11
12
13
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 11

def app_path
  @app_path
end

#deploymentObject (readonly)

Returns the value of attribute deployment.



11
12
13
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 11

def deployment
  @deployment
end

#envObject (readonly)

Returns the value of attribute env.



11
12
13
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 11

def env
  @env
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 11

def name
  @name
end

Instance Method Details

#appObject



48
49
50
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 48

def app
  @content.app
end

#clientObject



52
53
54
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 52

def client
  @content.client
end

#cluster_nameObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 23

def cluster_name
  return @cluster_name if defined?(@cluster_name)

  @cluster_name = @cluster
  @cluster_name ||= "kind-#{@config.name}" if @config.dev?
  @cluster_name = YAML.safe_load(File.read(cluster_path))[env.to_s] if cluster_path.exist? && (@cluster_name.nil? || @cluster_name.empty?)
  unless @cluster_name
    error "Cluster name unknown (not given explicitly and '#{cluster_path}' missing)"
    exit 1
  end
  @cluster_name
end

#readObject



43
44
45
46
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 43

def read
  t = Minfra::Cli::Templater.new(File.read(@app_path))
  @content = Hashie::Mash.new(JSON.parse(t.render({})))
end

#to_sObject



56
57
58
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 56

def to_s
  JSON.generate(@content, { indent: '  ', object_nl: "\n" })
end

#valid?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/minfra/cli/commands/stack/app_template.rb', line 36

def valid?
  @errors << "stack path #{@path} doesn't exist" unless @path.exist?

  @errors << "stack.rb file #{@app_path} doesn't exist" unless @app_path.exist?
  @errors.empty?
end