Sha256: 3a8e7177de34b70dafe42d9a574cd7a95655a847bfe106d1c6afd00095349a42

Contents?: true

Size: 1.81 KB

Versions: 6

Compression:

Stored size: 1.81 KB

Contents

require "redis"
require "logger"
require "pulse-meter/version"
require "pulse-meter/mixins/dumper"
require "pulse-meter/mixins/utils"
require "pulse-meter/mixins/cmd"
require "pulse-meter/observer"
require "pulse-meter/sensor"
require "pulse-meter/sensor/configuration"

require "pulse-meter/command_aggregator/async"
require "pulse-meter/command_aggregator/sync"
require "pulse-meter/command_aggregator/udp"

require "pulse-meter/udp_server"

module PulseMeter
  @@redis = nil

  # Returns global Redis client
  def self.redis
    @@redis 
  end

  # Sets global Redis client
  # @param redis [Redis] redis client
  def self.redis=(redis)
    @@redis = redis
  end

  # Returns global command aggegator (i.e. object that accumulates Redis commands emitted by events and sends them into client)
  def self.command_aggregator
    @@command_aggregator ||= PulseMeter::CommandAggregator::Async.instance
  end
  
  # Sets global command_aggregator
  # @param type [Symbol] type of command aggegator (:async or :sync)
  # @raise [ArgumentError] if type is none of :async, :sync
  def self.command_aggregator=(command_aggregator)
    @@command_aggregator = case command_aggregator
      when :sync; PulseMeter::CommandAggregator::Sync.instance
      when :async; PulseMeter::CommandAggregator::Async.instance
      else command_aggregator
    end
  end

  # Sets global logger for all PulseMeter error messages
  # @param logger [Logger] logger to be used
  def self.logger=(new_logger)
    @@logger = new_logger
  end

  # Returns global PulseMeter logger
  def self.logger
    @@logger ||= begin 
      logger = Logger.new($stderr)
      logger.datetime_format = '%Y-%m-%d %H:%M:%S.%3N'
      logger
    end
  end

  # Sends error message to PulseMeter logger
  # @param message [String] error message
  def self.error(msg)
    logger.error(msg)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pulse-meter-0.4.8 lib/pulse-meter.rb
pulse-meter-0.4.7 lib/pulse-meter.rb
pulse-meter-0.4.6 lib/pulse-meter.rb
pulse-meter-0.4.5 lib/pulse-meter.rb
pulse-meter-0.4.4 lib/pulse-meter.rb
pulse-meter-0.4.3 lib/pulse-meter.rb