Module: SmartQue

Defined in:
lib/smart_que.rb,
lib/smart_que/config.rb,
lib/smart_que/errors.rb,
lib/smart_que/version.rb,
lib/smart_que/publisher.rb,
lib/smart_que/publishers/base.rb

Defined Under Namespace

Modules: Publishers Classes: Config, Publisher, QueueNotFoundError

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.configObject

Methods related to configurations



14
15
16
# File 'lib/smart_que.rb', line 14

def self.config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



18
19
20
21
# File 'lib/smart_que.rb', line 18

def self.configure
  yield(config) if block_given?
  config
end

.default_log_fileObject



58
59
60
61
62
63
64
65
# File 'lib/smart_que.rb', line 58

def self.default_log_file
  log_file = "log/smart_que.log"
  dir = File.dirname(log_file)
  unless File.directory?(dir)
    FileUtils.mkdir_p(dir)
  end
  log_file
end

.establish_connectionObject

Establish bunny connection



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/smart_que.rb', line 24

def self.establish_connection
  return @conn if @conn

  @conn ||= Bunny.new(
    host: config.host,
    port: config.port,
    username: config.username,
    password: config.password)

  @conn.start
  @conn
end

.log(data) ⇒ Object

Logger



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/smart_que.rb', line 38

def self.log(data)
  env = ENV['RAILS_ENV'] || config.env

  proc = Proc.new do
    if config.logger
      @logger = config.logger
    else
      logfile = config.logfile || default_log_file
      @logger = Logger.new(logfile, 'weekly')
    end
  end


  return if (env == 'testing' or env == 'test')

  @logger ||= proc.call

  @logger.info(data.inspect)
end