Sha256: 0ebf4b2b8bca3273be93680479d41e809749f0aac351a867ed9df39c3a1912b7

Contents?: true

Size: 1.04 KB

Versions: 26

Compression:

Stored size: 1.04 KB

Contents

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

  class Configuration

    SETTINGS = [ :logger ]

    attr_writer *SETTINGS

    def initialize
      self.logger = Filum.logger

      Loquor.config do |config|
        config.endpoint = "http://www.meducation.net/system"
        config.substitute_values[true]  = ":__true__"
        config.substitute_values[false] = ":__false__"
      end
    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

26 entries across 26 versions & 1 rubygems

Version Path
meducation_sdk-1.5.5 lib/meducation_sdk/configuration.rb
meducation_sdk-1.5.4 lib/meducation_sdk/configuration.rb
meducation_sdk-1.5.3 lib/meducation_sdk/configuration.rb
meducation_sdk-1.5.2 lib/meducation_sdk/configuration.rb
meducation_sdk-1.5.1 lib/meducation_sdk/configuration.rb
meducation_sdk-1.5.0 lib/meducation_sdk/configuration.rb
meducation_sdk-1.4.4 lib/meducation_sdk/configuration.rb
meducation_sdk-1.4.3 lib/meducation_sdk/configuration.rb
meducation_sdk-1.4.2 lib/meducation_sdk/configuration.rb
meducation_sdk-1.4.1 lib/meducation_sdk/configuration.rb
meducation_sdk-1.4.0 lib/meducation_sdk/configuration.rb
meducation_sdk-1.3.0 lib/meducation_sdk/configuration.rb
meducation_sdk-1.2.6 lib/meducation_sdk/configuration.rb
meducation_sdk-1.2.5 lib/meducation_sdk/configuration.rb
meducation_sdk-1.2.4 lib/meducation_sdk/configuration.rb
meducation_sdk-1.2.3 lib/meducation_sdk/configuration.rb
meducation_sdk-1.2.2 lib/meducation_sdk/configuration.rb
meducation_sdk-1.2.1 lib/meducation_sdk/configuration.rb
meducation_sdk-1.2.0 lib/meducation_sdk/configuration.rb
meducation_sdk-1.1.2 lib/meducation_sdk/configuration.rb