Class: Convoy::Setup::Configuration::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/convoy/setup/configuration/writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, data) ⇒ Writer

Returns a new instance of Writer.



10
11
12
13
# File 'lib/convoy/setup/configuration/writer.rb', line 10

def initialize(path, data)
    @path = path
    @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/convoy/setup/configuration/writer.rb', line 8

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/convoy/setup/configuration/writer.rb', line 8

def path
  @path
end

Instance Method Details

#updateObject



24
25
26
27
28
29
30
31
32
# 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

#writeObject



15
16
17
18
19
20
21
22
# 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