Class: Minfra::Cli::StackM::ClientTemplate

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

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

Constructor Details

#initialize(stack_name, client_name, config) ⇒ ClientTemplate

Returns a new instance of ClientTemplate.



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

def initialize(stack_name, client_name, config)
  @stack_name  = stack_name
  @client_name = client_name
  @config      = OpenStruct.new
  @path = config.stacks_path.join(stack_name, "fxnet-client-#{client_name}-#{config.orch_env}.json")
  read
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/minfra/cli/commands/stack/client_template.rb', line 21

def exist?
  @path.exist?
end

#readObject



25
26
27
28
29
30
# File 'lib/minfra/cli/commands/stack/client_template.rb', line 25

def read
  return unless exist?

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

#to_sObject



32
33
34
# File 'lib/minfra/cli/commands/stack/client_template.rb', line 32

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