Module: RSpec::RemoteFixtures::Manifest

Defined in:
lib/rspec/remote_fixtures/manifest.rb

Overview

Keep track of fixture files, their digest, and their remote locations

Class Method Summary collapse

Class Method Details

.add_fixture!(relative_path, remote_path = nil, digest = nil) ⇒ Object

Support accepting a remote path and digest in case upload has already been performed



12
13
14
15
16
# File 'lib/rspec/remote_fixtures/manifest.rb', line 12

def self.add_fixture!(relative_path, remote_path = nil, digest = nil)
  digest ||= compute_digest(relative_path)
  remote_path ||= RemoteFixtures.upload(relative_path, digest)
  manifest[relative_path] = { 'digest' => digest, 'remote_path' => remote_path }
end

.compute_digest(path) ⇒ Object



42
43
44
# File 'lib/rspec/remote_fixtures/manifest.rb', line 42

def self.compute_digest(path)
  File.open(RemoteFixtures.full_path_from_relative(path), 'rb') { |f| Digest::MD5.hexdigest(f.read) }
end

.entry_for(relative_path) ⇒ Object



22
23
24
# File 'lib/rspec/remote_fixtures/manifest.rb', line 22

def self.entry_for(relative_path)
  manifest[relative_path]
end

.init_manifest!Object



33
34
35
36
# File 'lib/rspec/remote_fixtures/manifest.rb', line 33

def self.init_manifest!
  puts "Initializing rspec-remote-fixtures manifest #{manifest_path}"
  File.write(manifest_path, {}.to_json)
end

.manifestObject



26
27
28
29
30
31
# File 'lib/rspec/remote_fixtures/manifest.rb', line 26

def self.manifest
  return @manifest if defined?(@manifest)

  init_manifest! unless File.exist?(manifest_path)
  @manifest = JSON.parse(File.read(manifest_path))
end

.manifest_pathObject



38
39
40
# File 'lib/rspec/remote_fixtures/manifest.rb', line 38

def self.manifest_path
  Config.manifest_path
end

.persist_manifest!Object



18
19
20
# File 'lib/rspec/remote_fixtures/manifest.rb', line 18

def self.persist_manifest!
  File.write(manifest_path, manifest.to_json)
end