module AwsCftTools::Template::FileSystem

Manage template and parameter files.

Public Instance Methods

parameter_file() click to toggle source

Returns the path to the template parameters file.

@return [Pathname]

# File lib/aws_cft_tools/template/file_system.rb, line 23
def parameter_file
  filename_path(:parameter_dir, filename)
end
parameters_source() click to toggle source

The unparsed source of the parameters file for this template.

@return [String]

# File lib/aws_cft_tools/template/file_system.rb, line 39
def parameters_source
  @parameters_source ||= @options[:parameters_content] || read_file(parameter_file)
end
template_file() click to toggle source

Returns the path to the cloud formation template.

@return [Pathname]

# File lib/aws_cft_tools/template/file_system.rb, line 15
def template_file
  filename_path(:template_dir, filename)
end
template_source() click to toggle source

The unparsed source of the template.

@return [String]

# File lib/aws_cft_tools/template/file_system.rb, line 31
def template_source
  @template_source ||= @options[:template_content] || read_file(template_file)
end

Private Instance Methods

filename_path(dir, filename) click to toggle source

Given the filename relative to the template/parameter root and a symbol indicating which type of file to point to, returns the full path to the file

@return [Pathname]

# File lib/aws_cft_tools/template/file_system.rb, line 54
def filename_path(dir, filename)
  # we need to check .yaml, .yml, and .json versions
  filename = filename.to_s.sub(/\.[^.]*$/, '')
  base = @options[:root] + @options[dir]
  %w[.yaml .yml .json .rb].map { |ext| base + (filename + ext) }.detect(&:exist?)
end
read_file(file) click to toggle source
# File lib/aws_cft_tools/template/file_system.rb, line 45
def read_file(file)
  file ? file.read : nil
end