Class: CloudEncryptedSync::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_encrypted_sync/index.rb

Class Method Summary collapse

Class Method Details

.file_key(full_path) ⇒ Object



32
33
34
# File 'lib/cloud_encrypted_sync/index.rb', line 32

def file_key(full_path)
  Cryptographer.hash_data(relative_file_path(full_path) + File.open(full_path).read).to_s
end

.full_file_path(relative_path) ⇒ Object



24
25
26
# File 'lib/cloud_encrypted_sync/index.rb', line 24

def full_file_path(relative_path)
  normalized_sync_path+relative_path
end

.index_pathObject



28
29
30
# File 'lib/cloud_encrypted_sync/index.rb', line 28

def index_path
  "#{Configuration.data_folder_path}/#{index_filename}"
end

.localObject



6
7
8
# File 'lib/cloud_encrypted_sync/index.rb', line 6

def local
  @local ||= compile_local_hash
end

.remoteObject



10
11
12
13
14
15
16
# File 'lib/cloud_encrypted_sync/index.rb', line 10

def remote
  @remote ||= begin
    YAML.parse(liaison.pull(index_key)).to_ruby
  rescue Errors::NoSuchKey
    {}
  end
end

.writeObject



18
19
20
21
22
# File 'lib/cloud_encrypted_sync/index.rb', line 18

def write
  local_hash = compile_local_hash #recompile
  liaison.push(local_hash.to_yaml,index_key) #push to remote
  File.open(index_path, 'w') { |file| YAML.dump(local_hash, file) } #save to local
end