Module: GreenHat::ThingHistory
- Defined in:
- lib/greenhat/thing/history.rb
Overview
Helper for Remembering what files were
Class Method Summary collapse
- .add(name, type) ⇒ Object
-
.expire ⇒ Object
Date to Expire.
- .file ⇒ Object
- .files ⇒ Object
- .match(name) ⇒ Object
-
.match?(name) ⇒ Boolean
Initial Entry Point.
-
.read ⇒ Object
Read File / Remove Old Entries.
- .write ⇒ Object
Class Method Details
.add(name, type) ⇒ Object
36 37 38 39 40 |
# File 'lib/greenhat/thing/history.rb', line 36 def self.add(name, type) files[name] = { type: type, time: expire } write end |
.expire ⇒ Object
Date to Expire
43 44 45 |
# File 'lib/greenhat/thing/history.rb', line 43 def self.expire 2.weeks.from_now.to_i end |
.file ⇒ Object
23 24 25 |
# File 'lib/greenhat/thing/history.rb', line 23 def self.file Settings.history_file end |
.files ⇒ Object
4 5 6 7 8 |
# File 'lib/greenhat/thing/history.rb', line 4 def self.files @files ||= read @files end |
.match(name) ⇒ Object
32 33 34 |
# File 'lib/greenhat/thing/history.rb', line 32 def self.match(name) files.dig(name.to_sym, :type) end |
.match?(name) ⇒ Boolean
Initial Entry Point
28 29 30 |
# File 'lib/greenhat/thing/history.rb', line 28 def self.match?(name) files.key? name.to_sym end |
.read ⇒ Object
Read File / Remove Old Entries
11 12 13 14 15 16 17 18 19 20 21 |
# 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 ⇒ Object
47 48 49 |
# File 'lib/greenhat/thing/history.rb', line 47 def self.write File.write(file, Oj.dump(files)) end |