Class: GDSync::GoogleDriveFileSystem::Dir

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

Instance Method Summary collapse

Constructor Details

#initialize(fs, gd_collection, path) ⇒ Dir

Returns a new instance of Dir

Parameters:


93
94
95
96
97
# File 'lib/file_system/google_drive_file_system.rb', line 93

def initialize(fs, gd_collection, path)
  @fs = fs
  @collection = gd_collection
  @path = path
end

Instance Method Details

#create_dir!(title) ⇒ Object


121
122
123
124
125
126
127
128
129
# File 'lib/file_system/google_drive_file_system.rb', line 121

def create_dir!(title)
  begin
    created = @collection.create_subcollection(title)
    return Dir.new(@fs, created, ::File.join(@path, title)) unless created.nil?
  rescue
  end

  nil
end

#create_file_with_read_io!(io, title, mtime, birthtime) ⇒ Object


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/file_system/google_drive_file_system.rb', line 131

def create_file_with_read_io!(io, title, mtime, birthtime)
  params = {
    upload_source: io,
    content_type: 'application/octet-stream',
    fields: '*',
  }
  request_object = {
    name: title,
    parents: [@collection.id],
    modified_time: mtime.rfc3339,
    created_time: birthtime.rfc3339,
  }

  dest_file = nil

  begin
    api_file = @fs.session.drive.create_file(request_object, params)
    dest_file = @fs.session.wrap_api_file(api_file)
  rescue => e
    return nil
  end

  File.new(@fs, dest_file, ::File.join(@path, title))
end

#create_write_io!(title) ⇒ Object

Raises:


156
157
158
# File 'lib/file_system/google_drive_file_system.rb', line 156

def create_write_io!(title)
  raise NotSupportedError.new
end

#delete!Object


160
161
162
# File 'lib/file_system/google_drive_file_system.rb', line 160

def delete!
  @collection.delete
end

#entries(&block) ⇒ Object


103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/file_system/google_drive_file_system.rb', line 103

def entries(&block)
  @collection.files { |file|
    unless file.explicitly_trashed
      if file.is_a?(::GoogleDrive::Collection)
        d = Dir.new(@fs, file, ::File.join(@path, file.title))
        block.call(d)
      else
        f = File.new(@fs, file, ::File.join(@path, file.title))
        block.call(f)
      end
    end
  }
end

#fsObject


117
118
119
# File 'lib/file_system/google_drive_file_system.rb', line 117

def fs
  @fs
end

#idString

Get Google Drive file id.

Returns:

  • (String)

170
171
172
# File 'lib/file_system/google_drive_file_system.rb', line 170

def id
  @collection.id
end

#pathObject


164
165
166
# File 'lib/file_system/google_drive_file_system.rb', line 164

def path
  @path
end

#titleObject


99
100
101
# File 'lib/file_system/google_drive_file_system.rb', line 99

def title
  @collection.title
end