Sha256: a64403ad96e7633a4cade8ae4b677ba2b639b422278c1401a1a17fb027950eb4

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'forwardable'

require 'mwc/environment'
require 'mwc'

module Mwc
  # The compile preferences
  class Config
    extend Forwardable

    # @since 0.3.0
    # @api private
    delegate %i[environments] => :@default

    # @since 0.3.0
    # @api private
    LOCK = Mutex.new

    # @since 0.3.0
    # @api private
    attr_reader :default

    # :nodoc:
    def initialize(path = Mwc.root.join('.mwcrc'))
      @path = Pathname.new(path)
      @default = Environment.new
      load_config if exist?
    end

    # Check config file exists
    #
    # @return [TrueClass,FalseClass] exist or not
    #
    # @since 0.1.0
    # @api private
    def exist?
      @path.exist?
    end

    # Reload config
    #
    # @since 0.1.0
    # @api private
    def reload
      Mwc.config = Mwc.root.join('.mwcrc')
    end

    private

    # Laod .mwcrc config
    #
    # @since 0.1.0
    # @api private
    def load_config
      LOCK.synchronize { @default.instance_eval(@path.read) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mwc-0.4.0 lib/mwc/config.rb
mwc-0.3.0 lib/mwc/config.rb