Class: Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/karist/renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(env, root_path = ".") ⇒ Renderer

Returns a new instance of Renderer.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/karist/renderer.rb', line 4

def initialize(env, root_path=".")
  @env_path = "#{root_path}/environments/#{env}"
  @templates_path = "#{root_path}/templates"

  @release_file = File.read("#{@env_path}/releases.yml").then do |f|
    YAML.safe_load(f).then do |y|
      y.deep_symbolize_keys.then do |r|
        ReleaseFile.new(r, @env_path, @templates_path)
      end
    end
  end
end

Instance Method Details

#displayObject



21
22
23
# File 'lib/karist/renderer.rb', line 21

def display
  @release_file.display_all
end

#renderObject



17
18
19
# File 'lib/karist/renderer.rb', line 17

def render
  @release_file.render_all
end

#save_to_path!(path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/karist/renderer.rb', line 25

def save_to_path!(path)
  begin
    FileUtils.mkdir_p(path)
    @release_file.releases.each do |release|
      FileUtils.mkdir_p("#{path}/#{release.name}")
      release.results.each do |filename, result|
        r_filename = filename.split("/")
        case r_filename
        in [*subpath, filename]
          result_path = "#{path}/#{release.name}/#{subpath.join("/")}"
          FileUtils.mkdir_p(result_path)
          File.open("#{result_path}/#{filename}", "a+") do |f|
            f.write(result.deep_stringify_keys.to_yaml)
          end
        end
      end
    end
    return true
  rescue => e
    raise e
    return false
  end
end