Class: DockerSync::GlobalConfig

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/docker-sync/config/global_config.rb

Constant Summary collapse

DEFAULTS =

noinspection RubyStringKeysInHashInspection

{
  'update_check' => true,
  'update_last_check' => DateTime.new(2001, 1, 1).iso8601(9),
  'update_enforce' => true,
  'upgrade_status' => '',
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGlobalConfig

Returns a new instance of GlobalConfig.



28
29
30
# File 'lib/docker-sync/config/global_config.rb', line 28

def initialize
  load_global_config
end

Class Method Details

.loadObject



26
# File 'lib/docker-sync/config/global_config.rb', line 26

def self.load; instance end

Instance Method Details

#first_run?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/docker-sync/config/global_config.rb', line 44

def first_run?
  @first_run
end

#load_global_configObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/docker-sync/config/global_config.rb', line 32

def load_global_config
  @config_path = DockerSync::ConfigLocator.current_global_config_path
  if File.exist?(@config_path)
    @config = DockerSync::ConfigSerializer.default_deserializer_file(@config_path)
  end

  unless @config
    @config = DEFAULTS.dup
    @first_run = true
  end
end

#update!(updates) ⇒ Object

Updates and saves the configuration back to the file

Parameters:

  • updates (Object)


50
51
52
53
54
# File 'lib/docker-sync/config/global_config.rb', line 50

def update!(updates)
  @config.merge!(updates)

  File.open(@config_path, 'w') {|f| f.write @config.to_yaml }
end