Sha256: 00e0559592efd619782986e86b2dda86764929ffe9c6d818f4f887a84d735c0a

Contents?: true

Size: 967 Bytes

Versions: 8

Compression:

Stored size: 967 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, :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

8 entries across 8 versions & 1 rubygems

Version Path
meducation_sdk-0.8.0 lib/meducation_sdk/configuration.rb
meducation_sdk-0.7.0 lib/meducation_sdk/configuration.rb
meducation_sdk-0.6.1 lib/meducation_sdk/configuration.rb
meducation_sdk-0.6.0 lib/meducation_sdk/configuration.rb
meducation_sdk-0.5.0 lib/meducation_sdk/configuration.rb
meducation_sdk-0.4.1 lib/meducation_sdk/configuration.rb
meducation_sdk-0.4.0 lib/meducation_sdk/configuration.rb
meducation_sdk-0.3.4 lib/meducation_sdk/configuration.rb