Class: Quebert::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/quebert/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backendObject

Returns the value of attribute backend.



5
6
7
# File 'lib/quebert/configuration.rb', line 5

def backend
  @backend
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/quebert/configuration.rb', line 5

def logger
  @logger
end

#workerObject

Returns the value of attribute worker.



5
6
7
# File 'lib/quebert/configuration.rb', line 5

def worker
  @worker
end

Class Method Details

.from_hash(hash) ⇒ Object



37
38
39
# File 'lib/quebert/configuration.rb', line 37

def self.from_hash(hash)
  new.from_hash(hash) # Config this puppy up from a config hash
end

Instance Method Details

#after_job(job = nil, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/quebert/configuration.rb', line 52

def after_job(job = nil, &block)
  if job
    after_hooks.each do |h|
      h.call(job)
    end
  else
    after_hooks << block if block
  end
  self
end

#around_job(job = nil, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/quebert/configuration.rb', line 63

def around_job(job = nil, &block)
  if job
    around_hooks.each do |h|
      h.call(job)
    end
  else
    around_hooks << block if block
  end
  self
end

#before_job(job = nil, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/quebert/configuration.rb', line 41

def before_job(job = nil, &block)
  if job
    before_hooks.each do |h|
      h.call(job)
    end
  else
    before_hooks << block if block
  end
  self
end

#from_hash(hash) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/quebert/configuration.rb', line 23

def from_hash(hash)
  hash = Support.symbolize_keys(hash)
  # Find out backend from the registry and configure
  if backend = Quebert.backends[hash.delete(:backend).to_sym]
    # If the backend supports configuration, do it!
    self.backend = backend.respond_to?(:configure) ? backend.configure(Support.symbolize_keys(hash)) : backend.new
  end
  self
end

#log_file_path=(path) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/quebert/configuration.rb', line 15

def log_file_path=(path)
  self.logger = begin
    l = Logger.new(path)
    l.formatter = Logger::Formatter.new
    l
  end
end