Sha256: 9910d48cb39b498db68f3d96f5545200817948263859f4dcba1a2544be9448a0

Contents?: true

Size: 1.22 KB

Versions: 26

Compression:

Stored size: 1.22 KB

Contents

require 'singleton'
require 'forwardable'
require 'date'

require 'docker-sync/config/config_locator'
require 'docker-sync/config/config_serializer'

module DockerSync
  class GlobalConfig
    extend Forwardable
    include Singleton

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

    attr_reader :config
    private :config

    def_delegators :@config, :[], :to_h

    def self.load; instance end

    def initialize
      load_global_config
    end

    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

    def first_run?
      @first_run
    end

    # @param [Object] updates
    # Updates and saves the configuration back to the file
    def update!(updates)
      @config.merge!(updates)

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
docker-sync-1.0.5 lib/docker-sync/config/global_config.rb
docker-sync-1.0.4 lib/docker-sync/config/global_config.rb
docker-sync-1.0.3 lib/docker-sync/config/global_config.rb
docker-sync-1.0.2 lib/docker-sync/config/global_config.rb
docker-sync-1.0.1 lib/docker-sync/config/global_config.rb
docker-sync-1.0.0 lib/docker-sync/config/global_config.rb
docker-sync-0.7.2 lib/docker-sync/config/global_config.rb
docker-sync-0.7.1 lib/docker-sync/config/global_config.rb
docker-sync-0.7.0 lib/docker-sync/config/global_config.rb
docker-sync-0.6.0 lib/docker-sync/config/global_config.rb
docker-sync-0.5.14 lib/docker-sync/config/global_config.rb
docker-sync-0.5.13 lib/docker-sync/config/global_config.rb
docker-sync-0.5.11 lib/docker-sync/config/global_config.rb
docker-sync-0.5.11.pre.beta3 lib/docker-sync/config/global_config.rb
docker-sync-0.5.11.pre.beta2 lib/docker-sync/config/global_config.rb
docker-sync-0.5.11.pre.beta1 lib/docker-sync/config/global_config.rb
docker-sync-0.5.10 lib/docker-sync/config/global_config.rb
docker-sync-0.5.10.pre.beta1 lib/docker-sync/config/global_config.rb
docker-sync-0.5.9 lib/docker-sync/config/global_config.rb
docker-sync-0.5.8 lib/docker-sync/config/global_config.rb