Class: ActiveRecord::Snapshot::List

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/snapshot/files/list.rb

Class Method Summary collapse

Class Method Details

.add(version:, file:) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/active_record/snapshot/files/list.rb', line 13

def add(version:, file:)
  contents = File.read(path)
  File.open(path, "w") do |f|
    f.puts "#{version.to_i} #{File.basename(file)}"
    f.write contents
  end
end

.downloadObject



5
6
7
# File 'lib/active_record/snapshot/files/list.rb', line 5

def download
  s3.download_to(path)
end

.filenameObject



34
35
36
# File 'lib/active_record/snapshot/files/list.rb', line 34

def filename
  "snapshot_list".freeze
end

.get(version:) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/active_record/snapshot/files/list.rb', line 21

def get(version:)
  File.readlines(path).each do |line|
    version_str, filename = line.split(" ")
    return [version_str.to_i, filename] if version_str.to_i == version.to_i
  end
  []
end

.lastObject



29
30
31
32
# File 'lib/active_record/snapshot/files/list.rb', line 29

def last
  version_str, filename = File.open(path, &:readline).split(" ")
  [version_str.to_i, filename]
end

.pathObject



38
39
40
# File 'lib/active_record/snapshot/files/list.rb', line 38

def path
  config.store.local.join(filename).to_s.freeze
end

.uploadObject



9
10
11
# File 'lib/active_record/snapshot/files/list.rb', line 9

def upload
  s3.upload(path)
end