Sha256: cdbf01d59d55b7a2fc6247c9670b23d1c4f2b687ae938efee54e32e12c74f673

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

module PactBroker

  def self.configuration
    @@configuration ||= Configuration.default_configuration
  end

  class Configuration

    attr_accessor :log_dir, :database_connection, :auto_migrate_db, :use_hal_browser, :html_pact_renderer
    attr_accessor :validate_database_connection_config, :enable_diagnostic_endpoints, :version_parser
    attr_writer :logger

    def logger
      @logger ||= create_logger log_path
    end

    def self.default_configuration
      require 'pact_broker/versions/parse_semantic_version'
      config = Configuration.new
      config.log_dir = File.expand_path("./log")
      config.auto_migrate_db = true
      config.use_hal_browser = true
      config.html_pact_renderer = default_html_pact_render
      config.validate_database_connection_config = true
      config.enable_diagnostic_endpoints = true
      config.version_parser = PactBroker::Versions::ParseSemanticVersion
      config
    end

    def self.default_html_pact_render
      lambda { |pact|
        require 'pact_broker/api/renderers/html_pact_renderer'
        PactBroker::Api::Renderers::HtmlPactRenderer.call pact
      }
    end

    private

    def create_logger path
      FileUtils::mkdir_p File.dirname(path)
      logger = Logger.new(path)
      logger.level = Logger::DEBUG
      logger
    end

    def log_path
      log_dir + "/pact_broker.log"
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pact_broker-1.8.1 lib/pact_broker/configuration.rb
pact_broker-1.8.0 lib/pact_broker/configuration.rb
pact_broker-1.7.0 lib/pact_broker/configuration.rb