Class: GDSync::GoogleDriveFileSystem::File

Inherits:
AbstractFile
  • Object
show all
Defined in:
lib/file_system/google_drive_file_system.rb

Instance Method Summary collapse

Constructor Details

#initialize(fs, gd_file, path) ⇒ File


12
13
14
15
16
# File 'lib/file_system/google_drive_file_system.rb', line 12

def initialize(fs, gd_file, path)
  @fs = fs
  @file = gd_file
  @path = path
end

Instance Method Details

#birthtimeObject


84
85
86
# File 'lib/file_system/google_drive_file_system.rb', line 84

def birthtime
  @file.created_time
end

#copy_to(_dest_dir, _birthtime, _mtime) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/file_system/google_drive_file_system.rb', line 46

def copy_to(_dest_dir, _birthtime, _mtime)
  request_object = {
    name: title,
    parents: [_dest_dir.id],
    created_time: _birthtime.rfc3339,
    modified_time: _mtime.rfc3339,
  }
  params = {
  }
  api_file = @fs.session.drive.copy_file(@file.id, request_object, params)
  file = @fs.session.wrap_api_file(api_file)
  if file.nil?
    nil
  else
    File.new(@fs, file, ::File.join(_dest_dir.path, title))
  end
end

#create_read_ioObject

Raises:


38
39
40
# File 'lib/file_system/google_drive_file_system.rb', line 38

def create_read_io
  raise NotSupportedError.new
end

#delete!Object


76
77
78
# File 'lib/file_system/google_drive_file_system.rb', line 76

def delete!
  @file.delete
end

#fsObject


34
35
36
# File 'lib/file_system/google_drive_file_system.rb', line 34

def fs
  @fs
end

#md5Object


30
31
32
# File 'lib/file_system/google_drive_file_system.rb', line 30

def md5
  @file.api_file.md5_checksum
end

#mtimeObject


26
27
28
# File 'lib/file_system/google_drive_file_system.rb', line 26

def mtime
  @file.modified_time
end

#pathObject


80
81
82
# File 'lib/file_system/google_drive_file_system.rb', line 80

def path
  @path
end

#sizeObject


22
23
24
# File 'lib/file_system/google_drive_file_system.rb', line 22

def size
  @file.size.to_i
end

#titleObject


18
19
20
# File 'lib/file_system/google_drive_file_system.rb', line 18

def title
  @file.title
end

#update!(read_io, _mtime) ⇒ Object


64
65
66
67
68
69
70
71
72
73
74
# File 'lib/file_system/google_drive_file_system.rb', line 64

def update!(read_io, _mtime)
  request_object = {
    modified_time: _mtime.rfc3339,
  }
  params = {
    upload_source: read_io,
  }
  api_file = @fs.session.drive.update_file(@file.id, request_object, params)
  file = @fs.session.wrap_api_file(api_file)
  File.new(@fs, file, @path)
end

#write_to(write_io) ⇒ Object


42
43
44
# File 'lib/file_system/google_drive_file_system.rb', line 42

def write_to(write_io)
  @file.download_to_io(write_io)
end