class Convoy::Setup::Configuration::Writer

Attributes

data[R]
path[R]

Public Class Methods

new(path, data) click to toggle source
# File lib/convoy/setup/configuration/writer.rb, line 10
def initialize(path, data)
    @path = path
    @data = data
end

Public Instance Methods

update() click to toggle source
# File lib/convoy/setup/configuration/writer.rb, line 24
def update
    current_data = {}
    if File.exists? path
        current_data = Reader.new(path).read.data
    end
    @data = Convoy::Setup::Configuration::MergeTool.new(data, current_data).config_hash
    save_to_file
    Instance.new(path, data)
end
write() click to toggle source
# File lib/convoy/setup/configuration/writer.rb, line 15
def write
    if path && !File.exists?(path)
        save_to_file
        Instance.new(path, data)
    else
        Instance.blank
    end
end

Private Instance Methods

save_to_file() click to toggle source
# File lib/convoy/setup/configuration/writer.rb, line 36
def save_to_file
    current_path = File.expand_path(path)
    FileUtils.mkdir_p(File.dirname(current_path))
    File.open(current_path, "w") do |f|
        f.puts ::JSON.pretty_generate(data)
    end
end