Sha256: b6dc4a5f65c2db92d22d2987ea88a80d674a710be1e37892f59f9c20890ea5ce

Contents?: true

Size: 1.35 KB

Versions: 33

Compression:

Stored size: 1.35 KB

Contents

require 'pact_broker/configuration'
require 'pact_broker/logging'
require 'pact_broker/config/setting'

module PactBroker
  module Config
    class Load

      include PactBroker::Logging

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

      def initialize configuration
        @configuration = configuration
      end

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

      private

      attr_reader :configuration

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

      def set_value_on_configuration setting
        if configuration_attribute_exists? setting
          configuration.send("#{setting.name}=", get_value_from_setting(setting))
        else
          logger.warn("Could not load configuration setting \"#{setting.name}\" as there is no matching attribute on the Configuration class")
        end
      end

      def get_value_from_setting setting
        case setting.type
        when 'json'
          JSON.parse(setting.value, symbolize_names: true)
        when 'string'
          setting.value
        when 'integer'
          Integer(setting.value)
        when 'float'
          Float(setting.value)
        when 'boolean'
          setting.value == "1"
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
pact_broker-2.16.1 lib/pact_broker/config/load.rb
pact_broker-2.16.0 lib/pact_broker/config/load.rb
pact_broker-2.15.0 lib/pact_broker/config/load.rb
pact_broker-2.14.0 lib/pact_broker/config/load.rb
pact_broker-2.13.1 lib/pact_broker/config/load.rb
pact_broker-2.13.0 lib/pact_broker/config/load.rb
pact_broker-2.12.0 lib/pact_broker/config/load.rb
pact_broker-2.11.0 lib/pact_broker/config/load.rb
pact_broker-2.10.0 lib/pact_broker/config/load.rb
pact_broker-2.9.0 lib/pact_broker/config/load.rb
pact_broker-2.9.0.beta.5 lib/pact_broker/config/load.rb
pact_broker-2.8.0.beta.5 lib/pact_broker/config/load.rb
pact_broker-2.8.0.beta.4 lib/pact_broker/config/load.rb
pact_broker-2.7.0.beta.3 lib/pact_broker/config/load.rb
pact_broker-2.7.0.beta.2 lib/pact_broker/config/load.rb
pact_broker-2.7.0.beta.1 lib/pact_broker/config/load.rb
pact_broker-2.6.0 lib/pact_broker/config/load.rb
pact_broker-2.5.1 lib/pact_broker/config/load.rb
pact_broker-2.5.0 lib/pact_broker/config/load.rb
pact_broker-2.4.2 lib/pact_broker/config/load.rb