Sha256: 8cf72fb62fc1e405a2575f053ea1771f54e640b4b3808dc28c6d4aa9996b12d4

Contents?: true

Size: 1.21 KB

Versions: 28

Compression:

Stored size: 1.21 KB

Contents

module MeducationSDK
  class MeducationSDKError < StandardError
  end
  class MeducationSDKConfigurationError < MeducationSDKError
  end

  class Configuration

    SETTINGS = [ 
      :logger, 
      :recommender_host, :recommender_port 
    ]

    attr_writer *SETTINGS

    def initialize
      self.logger = Filum.logger

      Loquor.config do |config|
        config.endpoint = "http://spi.meducation.net"
        config.substitute_values[true]  = ":__true__"
        config.substitute_values[false] = ":__false__"
        config.retry_404s = true
      end

      self.recommender_host = "recommender.meducation.net"
      self.recommender_port = 4567
    end

    [:access_id, :secret_key, :endpoint, :cache].each do |setting|
      define_method "#{setting}=" do |val|
        Loquor.config.send("#{setting}=", val)
      end
    end

    def logger=(val)
      @logger = val
      Loquor.config.logger = val
    end

    SETTINGS.each do |setting|
      define_method setting do
        get_or_raise(setting)
      end
    end

    private

    def get_or_raise(setting)
      instance_variable_get("@#{setting.to_s}") ||
        raise(MeducationSDKConfigurationError.new("Configuration for #{setting} is not set"))
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
meducation_sdk-2.2.2 lib/meducation_sdk/configuration.rb
meducation_sdk-2.2.1 lib/meducation_sdk/configuration.rb
meducation_sdk-2.2.0 lib/meducation_sdk/configuration.rb
meducation_sdk-2.1.4 lib/meducation_sdk/configuration.rb
meducation_sdk-2.1.3 lib/meducation_sdk/configuration.rb
meducation_sdk-2.1.2 lib/meducation_sdk/configuration.rb
meducation_sdk-2.1.1 lib/meducation_sdk/configuration.rb
meducation_sdk-2.1.0 lib/meducation_sdk/configuration.rb
meducation_sdk-2.0.5 lib/meducation_sdk/configuration.rb
meducation_sdk-2.0.4 lib/meducation_sdk/configuration.rb
meducation_sdk-2.0.3 lib/meducation_sdk/configuration.rb
meducation_sdk-2.0.2 lib/meducation_sdk/configuration.rb
meducation_sdk-2.0.1 lib/meducation_sdk/configuration.rb
meducation_sdk-2.0.0 lib/meducation_sdk/configuration.rb
meducation_sdk-1.6.16 lib/meducation_sdk/configuration.rb
meducation_sdk-1.6.15 lib/meducation_sdk/configuration.rb
meducation_sdk-1.6.14 lib/meducation_sdk/configuration.rb
meducation_sdk-1.6.13 lib/meducation_sdk/configuration.rb
meducation_sdk-1.6.12 lib/meducation_sdk/configuration.rb
meducation_sdk-1.6.11 lib/meducation_sdk/configuration.rb