Sha256: dc32825768575cfb85ae7c3d88161105afc696f2111b8d1a22d4ff67b92eae7c

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

require 'active_support'
require 'json'
require 'logger'
require 'time'
require 'securerandom'
require 'qyu/version'
require 'qyu/config'
require 'qyu/factory'
require 'qyu/utils'
require 'qyu/errors'
require 'qyu/models'
require 'qyu/queue'
require 'qyu/store'
require 'qyu/workers'

module Qyu
  class << self
    def configure(queue:, store:, logger: nil)
      self.config = Qyu::Config.new(
        queue: queue,
        store: store
      )
      self.logger = logger || default_logger unless defined?(@@__logger)
      self.test_connections
    end

    def config
      fail 'Undefined configuration' unless defined?(@@__config)

      @@__config
    end
    alias configuration config

    def configured?
      defined?(@@__config)
    end

    def logger=(logger)
      @@__logger = logger
    end

    def logger
      @@__logger ||= default_logger
    end

    def queue
      @@__queue ||= Qyu::Factory::QueueFactory.get(config.queue)
    end

    def store
      @@__store ||= Qyu::Factory::StoreFactory.get(config.store)
    end

    def test_connections
      queue
      store
    end

    private

    def config=(config)
      fail 'Can not re-define configuration' if configured?
      fail 'Invalid configuration' unless config.is_a?(Qyu::Config)

      @@__config = config
    end

    def default_logger
      logger = Logger.new(STDOUT)
      logger.level = Logger::DEBUG
      logger
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
qyu-1.1.0 lib/qyu.rb
qyu-1.0.2 lib/qyu.rb
qyu-1.0.1 lib/qyu.rb
qyu-1.0.0 lib/qyu.rb