Class: Ufo::Docker::State::File

Inherits:
Base
  • Object
show all
Defined in:
lib/ufo/docker/state/file.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Utils::Pretty

#pretty_home, #pretty_path, #pretty_time

Methods included from Utils::Logging

#logger

Constructor Details

This class inherits a constructor from Ufo::Docker::State::Base

Instance Method Details

#current_dataObject



20
21
22
# File 'lib/ufo/docker/state/file.rb', line 20

def current_data
  ::File.exist?(state_path) ? YAML.load_file(state_path) : {}
end

#readObject



3
4
5
# File 'lib/ufo/docker/state/file.rb', line 3

def read
  current_data
end

#reminder_messageObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ufo/docker/state/file.rb', line 28

def reminder_message
  return unless Ufo.config.state.reminder
  repo = ENV['UFO_CENTRAL_REPO']
  return unless repo
  logger.info "It looks like you're using a central deployer pattern".color(:yellow)
  logger.info <<~EOL
    Remember to commit the state file:

        state file: #{pretty_path(state_path)}
        repo:       #{repo}

  EOL

  logger.info <<~EOL
    You can disable these reminder messages with:

    .ufo/config.rb

        Ufo.configure do |config|
          config.state.reminder = false
        end
  EOL
end

#state_pathObject



24
25
26
# File 'lib/ufo/docker/state/file.rb', line 24

def state_path
  "#{Ufo.root}/.ufo/state/#{Ufo.app}/#{Ufo.env}/data.yml"
end

#updateObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ufo/docker/state/file.rb', line 7

def update
  data = current_data
  data["base_image"] = @base_image

  pretty_path = state_path.sub("#{Ufo.root}/", "")
  FileUtils.mkdir_p(::File.dirname(state_path))
  IO.write(state_path, YAML.dump(data))

  logger.info "The #{pretty_path} base_image has been updated with the latest base image:".color(:green)
  logger.info "    #{@base_image}".color(:green)
  reminder_message
end