module GreenHat::ThingHistory

Helper for Remembering what files were

Public Class Methods

add(name, type) click to toggle source
# File lib/greenhat/thing/history.rb, line 36
def self.add(name, type)
  files[name] = { type: type, time: expire }

  write
end
expire() click to toggle source

Date to Expire

# File lib/greenhat/thing/history.rb, line 43
def self.expire
  2.weeks.from_now.to_i
end
file() click to toggle source
# File lib/greenhat/thing/history.rb, line 23
def self.file
  Settings.history_file
end
files() click to toggle source
# File lib/greenhat/thing/history.rb, line 4
def self.files
  @files ||= read

  @files
end
match(name) click to toggle source
# File lib/greenhat/thing/history.rb, line 32
def self.match(name)
  files.dig(name.to_sym, :type)
end
match?(name) click to toggle source

Initial Entry Point

# File lib/greenhat/thing/history.rb, line 28
def self.match?(name)
  files.key? name.to_sym
end
read() click to toggle source

Read File / Remove Old Entries

# File lib/greenhat/thing/history.rb, line 11
def self.read
  if File.exist? file
    results = Oj.load File.read(file)

    results.reject { |_k, v| Time.at(v.time) < Time.now }
  else
    {}
  end
ensure
  {}
end
write() click to toggle source
# File lib/greenhat/thing/history.rb, line 47
def self.write
  File.write(file, Oj.dump(files))
end