Class: Slacky::Config
- Inherits:
-
Object
- Object
- Slacky::Config
- Defined in:
- lib/slacky/config.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pid_file ⇒ Object
readonly
Returns the value of attribute pid_file.
Instance Method Summary collapse
- #config_dir ⇒ Object
- #down_name ⇒ Object
-
#initialize(name, opts = {}) ⇒ Config
constructor
A new instance of Config.
- #log(msg, ex = nil) ⇒ Object
- #slack_accept_channels ⇒ Object
- #slack_api_token ⇒ Object
- #slack_reject_channels ⇒ Object
- #whitelist_users ⇒ Object
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" = {} User.config = self end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
8 9 10 |
# File 'lib/slacky/config.rb', line 8 def db @db end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/slacky/config.rb', line 8 def name @name end |
#pid_file ⇒ Object (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_dir ⇒ Object
39 40 41 |
# File 'lib/slacky/config.rb', line 39 def config_dir ENV['CONFIG_DIR'] || "#{ENV['HOME']}/.#{down_name}" end |
#down_name ⇒ Object
31 32 33 |
# File 'lib/slacky/config.rb', line 31 def down_name @name.downcase end |
#log(msg, ex = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/slacky/config.rb', line 58 def log(msg, ex = nil) log = File.new(log_file, 'a') = Time.now.strftime('%Y-%m-%d %H:%M:%S') type = ex ? 'ERROR' : ' INFO' log.puts "#{type} #{timestamp} #{msg}" if ex log.puts ex. log.puts("Stacktrace:\n" + ex.backtrace.join("\n")) end log.flush end |
#slack_accept_channels ⇒ Object
48 49 50 51 |
# File 'lib/slacky/config.rb', line 48 def slack_accept_channels return nil unless ENV['ACCEPT_CHANNELS'] ENV['ACCEPT_CHANNELS'].split(',').map {|c| c.strip} end |
#slack_api_token ⇒ Object
35 36 37 |
# File 'lib/slacky/config.rb', line 35 def slack_api_token ENV['SLACK_API_TOKEN'] end |
#slack_reject_channels ⇒ Object
43 44 45 46 |
# File 'lib/slacky/config.rb', line 43 def slack_reject_channels return nil unless ENV['REJECT_CHANNELS'] ENV['REJECT_CHANNELS'].split(',').map {|c| c.strip} end |
#whitelist_users ⇒ Object
53 54 55 56 |
# File 'lib/slacky/config.rb', line 53 def whitelist_users return nil unless ENV['WHITELIST_USERS'] ENV['WHITELIST_USERS'].split(',').map {|u| u.strip} end |