Sha256: 8e598581ade6ba28d66de80ef998301393cf9ae2ae9ebdae9bc9eeacd5542e85

Contents?: true

Size: 959 Bytes

Versions: 4

Compression:

Stored size: 959 Bytes

Contents

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

  class Configuration

    SETTINGS = [ :logger ]

    attr_writer *SETTINGS

    def initialize
      Filum.config.logfile = "./log/loquor.log"
      Loquor.config.endpoint = "http://www.meducation.net/system"
      self.logger = Filum.logger
    end

    [:access_id, :secret_key, :endpoint].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

4 entries across 4 versions & 1 rubygems

Version Path
meducation_sdk-0.3.3 lib/meducation_sdk/configuration.rb
meducation_sdk-0.3.2 lib/meducation_sdk/configuration.rb
meducation_sdk-0.3.1 lib/meducation_sdk/configuration.rb
meducation_sdk-0.3.0 lib/meducation_sdk/configuration.rb