Class: Del::Configuration

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

Overview

This is used to contain all configuration.

Constant Summary collapse

SOCKET_FILE =
'/tmp/del.sock'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Configuration

Returns a new instance of Configuration.



18
19
20
21
22
# File 'lib/del/configuration.rb', line 18

def initialize(settings = {})
  @settings = settings
  @router = DefaultRouter.new
  @users = Repository.new(mapper: User)
end

Instance Attribute Details

#default_roomsObject



57
58
59
# File 'lib/del/configuration.rb', line 57

def default_rooms
  @default_rooms ||= settings.fetch(:rooms, [])
end

#hostObject



28
29
30
# File 'lib/del/configuration.rb', line 28

def host
  @host ||= settings.fetch(:host, 'chat.hipchat.com')
end

#jidObject



24
25
26
# File 'lib/del/configuration.rb', line 24

def jid
  @jid ||= settings.fetch(:jid)
end

#loggerObject



44
45
46
47
48
49
50
51
# File 'lib/del/configuration.rb', line 44

def logger
  @logger ||=
    begin
      x = Logger.new(STDOUT)
      x.level = settings.fetch(:log_level, Logger::INFO).to_i
      x
    end
end

#muc_domainObject



32
33
34
# File 'lib/del/configuration.rb', line 32

def muc_domain
  @muc_domain ||= settings.fetch(:muc_domain, 'conf.hipchat.com')
end

#nameObject



36
37
38
# File 'lib/del/configuration.rb', line 36

def name
  @name ||= settings.fetch(:full_name)
end

#passwordObject



40
41
42
# File 'lib/del/configuration.rb', line 40

def password
  @password ||= settings.fetch(:password)
end

#routerObject

Returns the value of attribute router.



7
8
9
# File 'lib/del/configuration.rb', line 7

def router
  @router
end

#socket_fileObject



53
54
55
# File 'lib/del/configuration.rb', line 53

def socket_file
  @socket_file ||= settings.fetch(:socket_file, SOCKET_FILE)
end

#usersObject

Returns the value of attribute users.



8
9
10
# File 'lib/del/configuration.rb', line 8

def users
  @users
end

Instance Method Details

#load(file) ⇒ Object



61
62
63
64
65
66
# File 'lib/del/configuration.rb', line 61

def load(file)
  return if file.nil?
  return Kernel.load(file) if File.exist?(file)

  download(file)
end