Module: Chillfile::SyncHelper

Included in:
Sync
Defined in:
lib/chillfile/helper/sync_helper.rb

Instance Method Summary collapse

Instance Method Details

#copy_doc(doc, path) ⇒ Object

COPIED



23
24
25
26
27
28
29
# File 'lib/chillfile/helper/sync_helper.rb', line 23

def copy_doc(doc, path)
  doc = create_doc(doc.checksum, path)
  
  # TODO keep metadata => make a deep clone here...
  
  doc
end

#create_doc(checksum, path) ⇒ Object

CREATED



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/chillfile/helper/sync_helper.rb', line 3

def create_doc(checksum, path)
  doc = Chillfile::Asset.new(:checksum => checksum, :path => path)
  doc.save
  begin
    file = File.open(path)
    doc.create_attachment(:file => file, :name => "master")
  ensure
    file.close
  end
  doc
end

#delete_doc(doc) ⇒ Object

DELETED



16
17
18
19
20
# File 'lib/chillfile/helper/sync_helper.rb', line 16

def delete_doc(doc)
  doc.deleted = true
  doc.save
  doc
end

#doc_save!(doc) ⇒ Object

FINALIZER



50
51
52
# File 'lib/chillfile/helper/sync_helper.rb', line 50

def doc_save!(doc)
  doc.save
end

#update_doc_attachment(doc, new_checksum) ⇒ Object

MODIFIED



38
39
40
41
42
43
44
45
46
47
# File 'lib/chillfile/helper/sync_helper.rb', line 38

def update_doc_attachment(doc, new_checksum)
  doc.checksum = new_checksum
  begin
    file = File.open(doc.path)
    doc.update_attachment(:file => file, :name => "master")
  ensure
    file.close
  end
  doc
end

#update_doc_path(doc, new_path) ⇒ Object

MOVED



32
33
34
35
# File 'lib/chillfile/helper/sync_helper.rb', line 32

def update_doc_path(doc, new_path)
  doc.path = new_path
  doc
end