class TwentyFortyEight::Logger
Attributes
entries[R]
Public Class Methods
destroy!(path)
click to toggle source
# File lib/TwentyFortyEight/logger.rb, line 31 def self.destroy!(path) full_path = File.expand_path path return unless File.exist? full_path File.delete full_path true end
load!(path)
click to toggle source
# File lib/TwentyFortyEight/logger.rb, line 25 def self.load!(path) full_path = File.expand_path path return unless File.exist? full_path new JSON.parse(File.read(full_path), symbolize_names: true) end
new(entries = [])
click to toggle source
# File lib/TwentyFortyEight/logger.rb, line 8 def initialize(entries = []) @entries = entries end
Public Instance Methods
<<(info_hsh)
click to toggle source
# File lib/TwentyFortyEight/logger.rb, line 12 def <<(info_hsh) entries << { time: (Time.now.to_f * 1000).to_i, info: info_hsh } end
write!(options = {})
click to toggle source
# File lib/TwentyFortyEight/logger.rb, line 16 def write!(options = {}) name = (options[:name] || "2048-#{Time.now.to_i}") + '.log.json' path = options[:path] || options[:dir] || Dir.pwd path = File.expand_path('./' + path) unless path.start_with? '/' return unless Dir.exist? path File.open(File.join(path, name), 'w') { |f| f.write @entries.to_json } end