Sha256: 79825d0723f7d712431686f144be0652ac80450d9de6ca3b7957aa3d64dfc0ff

Contents?: true

Size: 1.59 KB

Versions: 42

Compression:

Stored size: 1.59 KB

Contents

require "pact_broker/configuration"
require "pact_broker/logging"
require "pact_broker/config/setting"
require "pact_broker/config/space_delimited_string_list"

module PactBroker
  module Config
    class Load

      include PactBroker::Logging

      def self.call runtime_configuration
        new(runtime_configuration).call
      end

      def initialize runtime_configuration
        @runtime_configuration = runtime_configuration
      end

      def call
        Setting.each do | setting |
          set_value_on_configuration setting
        end
      end

      private

      attr_reader :runtime_configuration

      def configuration_attribute_exists? setting
        runtime_configuration.respond_to?("#{setting.name}=")
      end

      def unset_or_value_from_default? setting
        setting_source(setting).nil? || setting_source(setting)[:type] == :defaults
      end

      def setting_source(setting)
        runtime_configuration.to_source_trace.dig(setting.name, :source)
      end

      def set_value_on_configuration setting
        if configuration_attribute_exists?(setting)
          if unset_or_value_from_default?(setting)
            runtime_configuration.send("#{setting.name}=", setting.value_object)
          else
            logger.debug("Ignoring #{setting.name} configuration from database, as it has been set by another source #{setting_source(setting)}")
          end
        else
          logger.warn("Could not load configuration setting \"#{setting.name}\" as there is no matching attribute on the #{runtime_configuration.class} class")
        end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/config/load.rb
pact_broker-2.111.0 lib/pact_broker/config/load.rb
pact_broker-2.109.1 lib/pact_broker/config/load.rb
pact_broker-2.109.0 lib/pact_broker/config/load.rb
pact_broker-2.108.0 lib/pact_broker/config/load.rb
pact_broker-2.107.1 lib/pact_broker/config/load.rb
pact_broker-2.107.0 lib/pact_broker/config/load.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/config/load.rb
pact_broker-2.106.0 lib/pact_broker/config/load.rb
pact_broker-2.105.0 lib/pact_broker/config/load.rb
pact_broker-2.104.0 lib/pact_broker/config/load.rb
pact_broker-2.103.0 lib/pact_broker/config/load.rb
pact_broker-2.102.2 lib/pact_broker/config/load.rb
pact_broker-2.102.1 lib/pact_broker/config/load.rb
pact_broker-2.102.0 lib/pact_broker/config/load.rb
pact_broker-2.101.0 lib/pact_broker/config/load.rb
pact_broker-2.100.0 lib/pact_broker/config/load.rb
pact_broker-2.99.0 lib/pact_broker/config/load.rb
pact_broker-2.98.0 lib/pact_broker/config/load.rb
pact_broker-2.97.0 lib/pact_broker/config/load.rb