Class: KNSEmailEndpoint::Configuration

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

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Connection Handling



69
70
71
72
73
74
# File 'lib/kns_email_endpoint/configuration.rb', line 69

def [](name)
  @@connections.each do |conn| 
    return conn if conn["name"] == name
  end
  raise "Invalid connection (#{name})" 
end

.connectionsObject



64
# File 'lib/kns_email_endpoint/configuration.rb', line 64

def connections; @@connections ||= [] end

.each_connectionObject



76
77
78
79
80
# File 'lib/kns_email_endpoint/configuration.rb', line 76

def each_connection
  @@connections.each do |conn|
    yield Connection.new conn["name"]
  end
end

.load_from_file(yaml_file) ⇒ Object



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

def load_from_file(yaml_file)
  conf = YAML.load_file(yaml_file)
  @@logdir = conf["logdir"] if conf["logdir"]
  @@work_threads = conf["workthreads"] if conf["workthreads"]
  @@poll_delay = conf["polldelayinseconds"] if conf["polldelayinseconds"]
  @@log_level = conf["logginglevel"] if conf["logginglevel"]
  @@connections = conf["connections"] if conf["connections"]
  self.storage = conf["storage"] || {}
end

.logObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/kns_email_endpoint/configuration.rb', line 34

def log
  return @@logger if defined?(@@logger) && ! @logger.nil?
  if @@logdir && ! @@logdir.empty?
    FileUtils.mkdir_p @@logdir unless @@logdir == "" || @@logdir.nil?
    log_dest = File.join(@@logdir, 'email_endpoint.log')
  else
    log_dest = STDOUT
  end
  @@logger = Logger.new(log_dest, "daily")
  @@logger.level = eval("Logger::#{@@log_level.upcase}") rescue Logger::DEBUG
  return @@logger
end

.log_level=(l) ⇒ Object



47
48
49
50
51
# File 'lib/kns_email_endpoint/configuration.rb', line 47

def log_level=(l)
  @@log_level = l
  @@log = nil
  return @@log_level
end

.logdirObject



63
# File 'lib/kns_email_endpoint/configuration.rb', line 63

def logdir; @@logdir ||= "" end

.poll_delayObject



62
# File 'lib/kns_email_endpoint/configuration.rb', line 62

def poll_delay; @@poll_delay ||= 30 end

.storageObject



65
# File 'lib/kns_email_endpoint/configuration.rb', line 65

def storage; @@storage ||= {} end

.storage=(opts) ⇒ Object



53
54
55
56
57
58
# File 'lib/kns_email_endpoint/configuration.rb', line 53

def storage=(opts)
  @@storage = opts
  engine = opts.delete("engine")
  @@storage_engine = MessageState.set_storage(engine, opts)
  return @@storage
end

.to_hObject



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

def to_h
  {
    :logdir => logdir,
    :work_threads => work_threads,
    :poll_delay => poll_delay,
    :storage => storage,
    :connections => connections
  }
end

.work_threadsObject

defaults



61
# File 'lib/kns_email_endpoint/configuration.rb', line 61

def work_threads; @@work_threads ||= 10 end