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
Constructor Details
#initialize(name, opts = {}) ⇒ Config
10 11 12 13 14 15 16 17 18 19 20 |
# 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" @db = PG.connect(db_connect_params) User.db = @db User.initialize_table = {} 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
30 31 32 |
# File 'lib/slacky/config.rb', line 30 def config_dir ENV['CONFIG_DIR'] || "#{ENV['HOME']}/.#{down_name}" end |
#down_name ⇒ Object
22 23 24 |
# File 'lib/slacky/config.rb', line 22 def down_name @name.downcase end |
#log(msg, ex = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/slacky/config.rb', line 44 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
39 40 41 42 |
# File 'lib/slacky/config.rb', line 39 def slack_accept_channels return nil unless ENV['ACCEPT_CHANNELS'] ENV['ACCEPT_CHANNELS'].split(',').map {|c| c.strip} end |
#slack_api_token ⇒ Object
26 27 28 |
# File 'lib/slacky/config.rb', line 26 def slack_api_token ENV['SLACK_API_TOKEN'] end |
#slack_reject_channels ⇒ Object
34 35 36 37 |
# File 'lib/slacky/config.rb', line 34 def slack_reject_channels return nil unless ENV['REJECT_CHANNELS'] ENV['REJECT_CHANNELS'].split(',').map {|c| c.strip} end |