Module: Coinbot::BotConf
- Defined in:
- lib/coinbot/bot_conf.rb
Overview
This plugin is used to read & write to the bot conf file.
Class Method Summary collapse
-
.help ⇒ Object
Display Usage for this Module.
-
.read(opts = {}) ⇒ Object
Deserialize Coinbot Bot Conf.
-
.update(opts = {}) ⇒ Object
Update Key/Value Pair in Bot Conf and Serialize to YAML File.
Class Method Details
.help ⇒ Object
Display Usage for this Module
70 71 72 73 74 |
# File 'lib/coinbot/bot_conf.rb', line 70 public_class_method def self.help puts "USAGE: logger = #{self}.create() " end |
.read(opts = {}) ⇒ Object
Deserialize Coinbot Bot Conf
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/coinbot/bot_conf.rb', line 9 public_class_method def self.read(opts = {}) option_choice = opts[:option_choice] bot_conf_file = "#{option_choice.repo_root}/etc/bot_confs/#{option_choice.symbol}_bot_conf.yaml" unless File.exist?(bot_conf_file) FileUtils.cp( "#{option_choice.repo_root}/etc/bot_confs/BOT_CONF.TEMPLATE", bot_conf_file ) end YAML.load_file( bot_conf_file, symbolize_names: true ) rescue Errno::ENOENT, NoMethodError => e File.open('/tmp/coinbot-errors.txt', 'a') do |f| f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z') f.puts "#{self}\n#{e}\n\n\n" end retry rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |
.update(opts = {}) ⇒ Object
Update Key/Value Pair in Bot Conf and Serialize to YAML File
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/coinbot/bot_conf.rb', line 41 public_class_method def self.update(opts = {}) option_choice = opts[:option_choice] bot_conf = opts[:bot_conf] key = opts[:key].to_s.to_sym value = opts[:value] bot_conf_file = "#{option_choice.repo_root}/etc/bot_confs/#{option_choice.symbol}_bot_conf.yaml" bot_conf[key] = value File.open(bot_conf_file, 'w') do |bcf| bcf.write bot_conf.to_yaml end rescue Errno::ENOENT, NoMethodError => e File.open('/tmp/coinbot-errors.txt', 'a') do |f| f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z') f.puts "#{self}\n#{e}\n\n\n" end retry rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Coinbot.exit_gracefully(which_self: self) rescue StandardError => e # Produce a Stacktrace for anything else Curses.close_screen raise e end |