Class: Slacky::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/slacky/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}) ⇒ Config

Returns a new instance of Config.



10
11
12
13
14
15
16
17
# File 'lib/slacky/config.rb', line 10

def initialize(name, opts = {})
  @name = name
  Dotenv.load ".env", "#{config_dir}/.env"
  FileUtils.mkdir config_dir unless File.directory? config_dir
  @pid_file = "#{config_dir}/pid"
  @timestamps = {}
  User.config = self
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



8
9
10
# File 'lib/slacky/config.rb', line 8

def db
  @db
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/slacky/config.rb', line 8

def name
  @name
end

#pid_fileObject (readonly)

Returns the value of attribute pid_file.



8
9
10
# File 'lib/slacky/config.rb', line 8

def pid_file
  @pid_file
end

Instance Method Details

#config_dirObject



33
34
35
# File 'lib/slacky/config.rb', line 33

def config_dir
  ENV['CONFIG_DIR'] || "#{ENV['HOME']}/.#{down_name}"
end

#down_nameObject



25
26
27
# File 'lib/slacky/config.rb', line 25

def down_name
  @name.downcase
end

#log(msg, ex = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/slacky/config.rb', line 52

def log(msg, ex = nil)
  log = File.new(log_file, 'a')
  timestamp = Time.now.strftime('%Y-%m-%d %H:%M:%S')
  type = ex ? 'ERROR' : ' INFO'
  log.puts "#{type}  #{timestamp}  #{msg}"
  if ex
    log.puts ex.message
    log.puts("Stacktrace:\n" + ex.backtrace.join("\n"))
  end
  log.flush
end

#slack_accept_channelsObject



42
43
44
45
# File 'lib/slacky/config.rb', line 42

def slack_accept_channels
  return nil unless ENV['ACCEPT_CHANNELS']
  ENV['ACCEPT_CHANNELS'].split(',').map {|c| c.strip}
end

#slack_api_tokenObject



29
30
31
# File 'lib/slacky/config.rb', line 29

def slack_api_token
  ENV['SLACK_API_TOKEN']
end

#slack_reject_channelsObject



37
38
39
40
# File 'lib/slacky/config.rb', line 37

def slack_reject_channels
  return nil unless ENV['REJECT_CHANNELS']
  ENV['REJECT_CHANNELS'].split(',').map {|c| c.strip}
end

#whitelist_usersObject



47
48
49
50
# File 'lib/slacky/config.rb', line 47

def whitelist_users
  return nil unless ENV['WHITELIST_USERS']
  ENV['WHITELIST_USERS'].split(',').map {|u| u.strip}
end