Sha256: 9ab8db6a0d907d1f5499e4115934743c9f4445e650e6721bbbb56f43779de40e

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 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 = is_rake_running? ? :overwrite : :update
    c
  end

  #Would love a better way of determining this! It sure won't work on windows.
  def self.is_rake_running?
    `ps -ef | grep rake | grep #{Process.ppid} | grep -v 'grep'`.size > 0
  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.5 lib/pact/configuration.rb
pact-1.0.4 lib/pact/configuration.rb
pact-1.0.3 lib/pact/configuration.rb
pact-1.0.2 lib/pact/configuration.rb