Class: GDSync::GoogleDriveFileSystem

Inherits:
FileSystem show all
Defined in:
lib/file_system/google_drive_file_system.rb

Defined Under Namespace

Classes: Dir, File

Constant Summary collapse

URL_SCHEMA =
'googledrive://'

Instance Method Summary collapse

Constructor Details

#initialize(gd_session) ⇒ GoogleDriveFileSystem

Returns a new instance of GoogleDriveFileSystem

Parameters:

  • gd_session (GoogleDrive::Session)

176
177
178
# File 'lib/file_system/google_drive_file_system.rb', line 176

def initialize(gd_session)
  @session = gd_session
end

Instance Method Details

#can_create_io_stream?Boolean

Returns:

  • (Boolean)

180
181
182
# File 'lib/file_system/google_drive_file_system.rb', line 180

def can_create_io_stream?
  false
end

#find(file) ⇒ Object


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/file_system/google_drive_file_system.rb', line 184

def find(file)
  unless file.start_with?(URL_SCHEMA)
    return nil
  end

  if file === URL_SCHEMA
    return Dir.new(self, @session.root_collection, URL_SCHEMA)
  end

  if file.end_with?('/')
    file = file.slice(0, file.size - 1)
  end
  path_elements = file.split(URL_SCHEMA)[1].split('/')
  path = URL_SCHEMA

  collection = @session.root_collection
  for path_element in path_elements do
    path = ::File.join(path, path_element)

    # find directory first.
    child = collection.subcollection_by_title(path_element)
    unless child.nil?
      child = nil if child.explicitly_trashed
    end

    if file === path
      if child.nil?
        # directory not found. then search file
        child = collection.file_by_title(path_element)
        unless child.nil?
          child = nil if child.explicitly_trashed
        end
        if child.nil?
          return nil
        else
          return File.new(self, child, path)
        end
      else
        return Dir.new(self, child, path)
      end
    else
      if child.nil?
        return nil
      else
        collection = child
      end
    end
  end

  nil
end

#sessionGoogleDrive::Session

Get GoogleDrive::Session object.

Returns:

  • (GoogleDrive::Session)

238
239
240
# File 'lib/file_system/google_drive_file_system.rb', line 238

def session
  @session
end