Class: S3fsr

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

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ S3fsr

Returns a new instance of S3fsr.



252
253
254
# File 'lib/s3fsr.rb', line 252

def initialize(root)
  @root = root
end

Instance Method Details

#can_delete?(path) ⇒ Boolean

Returns:

  • (Boolean)


294
295
296
# File 'lib/s3fsr.rb', line 294

def can_delete?(path)
  o = get_object(path) ; o == nil ? false : o.is_file?
end

#can_mkdir?(path) ⇒ Boolean

Returns:

  • (Boolean)


300
301
302
303
# File 'lib/s3fsr.rb', line 300

def can_mkdir?(path)
  return false if get_object(path) != nil
  get_parent_object(path).is_directory?
end

#can_rmdir?(path) ⇒ Boolean

Returns:

  • (Boolean)


308
309
310
311
312
# File 'lib/s3fsr.rb', line 308

def can_rmdir?(path)
  return false if path == '/'
  return false unless get_object(path).is_directory?
  get_object(path).contents.length == 0
end

#can_write?(path) ⇒ Boolean

Returns:

  • (Boolean)


274
275
276
277
278
279
280
281
# File 'lib/s3fsr.rb', line 274

def can_write?(path)
  o = get_object(path)
  if o != nil
    o.is_file?
  else
    d = get_parent_object(path) ; d == nil ? false : d.can_write_files?
  end
end

#contents(path) ⇒ Object



255
256
257
258
# File 'lib/s3fsr.rb', line 255

def contents(path)
  o = get_object(path)
  o == nil ? "" : o.contents
end

#delete(path) ⇒ Object



297
298
299
# File 'lib/s3fsr.rb', line 297

def delete(path)
  get_object(path).delete
end

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


259
260
261
# File 'lib/s3fsr.rb', line 259

def directory?(path)
  o = get_object(path) ; o == nil ? false : o.is_directory?
end

#executable?(path) ⇒ Boolean

Returns:

  • (Boolean)


265
266
267
# File 'lib/s3fsr.rb', line 265

def executable?(path)
  false
end

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


262
263
264
# File 'lib/s3fsr.rb', line 262

def file?(path)
  o = get_object(path) ; o == nil ? false : o.is_file?
end

#mkdir(path) ⇒ Object



304
305
306
307
# File 'lib/s3fsr.rb', line 304

def mkdir(path)
  child_key = @root.path_to_key path[1..-1]
  get_parent_object(path).create_dir(child_key)
end

#read_file(path) ⇒ Object



271
272
273
# File 'lib/s3fsr.rb', line 271

def read_file(path)
  get_object(path).value
end

#rmdir(path) ⇒ Object



313
314
315
# File 'lib/s3fsr.rb', line 313

def rmdir(path)
  get_object(path).delete
end

#size(path) ⇒ Object



268
269
270
# File 'lib/s3fsr.rb', line 268

def size(path)
  get_object(path).size
end

#touch(path) ⇒ Object



316
317
318
319
320
321
322
323
# File 'lib/s3fsr.rb', line 316

def touch(path)
  o = get_object(path)
  if o != nil
    o.touch
  else
    write_to(path, "")
  end
end

#write_to(path, data) ⇒ Object



282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/s3fsr.rb', line 282

def write_to(path, data)
  o = get_object(path)
  if o != nil
    o.write data
  else
    d = get_parent_object(path)
    if d != nil
      child_key = @root.path_to_key path[1..-1]
      d.create_file(child_key, data)
    end
  end
end