Sha256: 84eb3281f4a0d1e79ea52a30bd78df02f10d2ec67c7e2dc74fc3c5baf4fd643f

Contents?: true

Size: 1.21 KB

Versions: 28

Compression:

Stored size: 1.21 KB

Contents

require 'singleton'
require 'forwardable'

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

28 entries across 28 versions & 1 rubygems

Version Path
docker-sync-0.5.1 lib/docker-sync/config/global_config.rb
docker-sync-0.5.0 lib/docker-sync/config/global_config.rb
docker-sync-0.5.0.pre.rc1 lib/docker-sync/config/global_config.rb
docker-sync-0.5.0.pre.beta3 lib/docker-sync/config/global_config.rb
docker-sync-0.5.0.pre.beta2 lib/docker-sync/config/global_config.rb
docker-sync-0.5.0.pre.beta1 lib/docker-sync/config/global_config.rb
docker-sync-0.4.6 lib/docker-sync/config/global_config.rb
docker-sync-0.4.5 lib/docker-sync/config/global_config.rb
docker-sync-0.4.5.beta1 lib/docker-sync/config/global_config.rb
docker-sync-0.4.4 lib/docker-sync/config/global_config.rb
docker-sync-0.4.4.beta2 lib/docker-sync/config/global_config.rb
docker-sync-0.4.4.beta1 lib/docker-sync/config/global_config.rb
docker-sync-0.4.3 lib/docker-sync/config/global_config.rb
docker-sync-0.4.3.pre.beta1 lib/docker-sync/config/global_config.rb
docker-sync-0.4.2 lib/docker-sync/config/global_config.rb
docker-sync-0.4.1 lib/docker-sync/config/global_config.rb
docker-sync-0.4.1.pre.beta2 lib/docker-sync/config/global_config.rb
docker-sync-0.4.1.pre.beta1 lib/docker-sync/config/global_config.rb
docker-sync-0.4.0 lib/docker-sync/config/global_config.rb
docker-sync-0.4.0.pre.beta2 lib/docker-sync/config/global_config.rb