Class: Snappier::FilePersistence
- Inherits:
-
Object
- Object
- Snappier::FilePersistence
- Defined in:
- lib/snappier/file_persistence.rb
Instance Method Summary collapse
Instance Method Details
#each(type:, id:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/snappier/file_persistence.rb', line 13 def each(type:, id:) dir_path = File.join("tmp", "snappier", type.to_s, id) Dir["#{dir_path}/*.yml"].each do |file_path| milliseconds = File.basename(file_path).split(".").first yield( { at: Time.at(milliseconds.to_i / 1000), content: YAML.load_file(file_path) } ) end end |
#persist(type:, id:, at:, args:) ⇒ Object
7 8 9 10 11 |
# File 'lib/snappier/file_persistence.rb', line 7 def persist(type:, id:, at:, args:) path = File.join("tmp", "snappier", type, id, "#{at}.yml") FileUtils.mkdir_p(File.dirname(path)) File.write(path, args.to_yaml) end |