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.96.0 lib/pact_broker/config/load.rb
pact_broker-2.95.1 lib/pact_broker/config/load.rb
pact_broker-2.95.0 lib/pact_broker/config/load.rb
pact_broker-2.94.0 lib/pact_broker/config/load.rb
pact_broker-2.93.4 lib/pact_broker/config/load.rb
pact_broker-2.93.3 lib/pact_broker/config/load.rb
pact_broker-2.93.2 lib/pact_broker/config/load.rb
pact_broker-2.93.1 lib/pact_broker/config/load.rb
pact_broker-2.93.0 lib/pact_broker/config/load.rb
pact_broker-2.92.0 lib/pact_broker/config/load.rb
pact_broker-2.91.0 lib/pact_broker/config/load.rb
pact_broker-2.90.0 lib/pact_broker/config/load.rb
pact_broker-2.89.1 lib/pact_broker/config/load.rb
pact_broker-2.89.0 lib/pact_broker/config/load.rb
pact_broker-2.88.0 lib/pact_broker/config/load.rb
pact_broker-2.87.0 lib/pact_broker/config/load.rb
pact_broker-2.86.0 lib/pact_broker/config/load.rb
pact_broker-2.85.1 lib/pact_broker/config/load.rb
pact_broker-2.85.0 lib/pact_broker/config/load.rb
pact_broker-2.84.0 lib/pact_broker/config/load.rb