Sha256: 5508eecae2e688fbe4c4f78ae21600b32997b9fde7d7cd14a88325e4be51f780

Contents?: true

Size: 1.12 KB

Versions: 14

Compression:

Stored size: 1.12 KB

Contents

require 'logger'

# Configure the api
#
# === Available settings
#
# * [+debug+] Prints debugging information to logger. Default +false+. Errors still will be logged
# * [+logger+] Configure the logger; set this if you want to use a custom logger.
#
# === Usage
#
#   Embedly.configure do |config|
#     # prints debug messages
#     config.debug = true
#
#     # customize the logger
#     config.logger = MyAwesomeLogger.new(STDERR)
#   end
#
class Embedly::Configuration
  attr_accessor :key, :typhoeus # :nodoc:

  def initialize # :nodoc:
    self.reset
  end

  def debug? # :nodoc:
    self.logger.debug?
  end

  def debug=(true_or_false) # :nodoc:
    set_logger_level(true_or_false)
  end

  def logger # :nodoc:
    @logger ||= default_logger
  end

  def logger=(log) # :nodoc:
    @logger = log
    set_logger_level(self.debug?)
  end

  # reset configuration
  def reset
    self.logger = default_logger
    self.debug  = false
  end

  private

  def default_logger # :nodoc:
    Logger.new(STDERR)
  end

  def set_logger_level(true_or_false) # :nodoc:
    logger.level = true_or_false ? Logger::DEBUG : Logger::ERROR
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
embedly-1.7.1 lib/embedly/configuration.rb
embedly-1.7.0 lib/embedly/configuration.rb
embedly-1.6.0 lib/embedly/configuration.rb
embedly-1.5.6 lib/embedly/configuration.rb
embedly-1.5.5 lib/embedly/configuration.rb
embedly-1.5.4 lib/embedly/configuration.rb
embedly-1.5.3 lib/embedly/configuration.rb
embedly-1.5.2 lib/embedly/configuration.rb
embedly-1.5.1 lib/embedly/configuration.rb
embedly-1.5.0 lib/embedly/configuration.rb
embedly-1.4.1 lib/embedly/configuration.rb
embedly-1.4.0 lib/embedly/configuration.rb
anideo-embedly-1.3.0 lib/embedly/configuration.rb
embedly-1.3.0 lib/embedly/configuration.rb