Sha256: 6029c5f2cec7e59a6ffba7fb5e82e58f222a427d5c4a41034a01a76541c76e49

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

require 'ostruct'
require 'logger'

module Pact

  class Configuration
    attr_accessor :pact_dir
    attr_accessor :log_dir
    attr_accessor :logger
    attr_accessor :tmp_dir
    attr_accessor :pactfile_write_mode

    def log_path
      log_dir + "/pact_gem.log"
    end
  end

  def self.configuration
    @configuration ||= default_configuration
  end

  def self.configure
    yield configuration
    FileUtils::mkdir_p configuration.tmp_dir
  end

  def self.clear_configuration
    @configuration = default_configuration
  end

  private

  def self.default_configuration
    c = Configuration.new
    c.pact_dir = File.expand_path('./spec/pacts')
    c.tmp_dir = File.expand_path('./tmp/pacts')
    c.log_dir = default_log_dir
    c.logger = default_logger c.log_path
    c.pactfile_write_mode = defined?(Rake) ? :overwrite : :update
    c
  end

  def self.default_log_dir
    File.expand_path("./log")
  end

  def self.default_logger path
    FileUtils::mkdir_p File.dirname(path)
    logger = Logger.new(path)
    logger.level = Logger::INFO
    logger
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pact-1.0.0 lib/pact/configuration.rb
pact-0.1.37 lib/pact/configuration.rb
pact-0.1.35 lib/pact/configuration.rb
pact-0.1.28 lib/pact/configuration.rb