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.



194
195
196
# File 'lib/s3fsr.rb', line 194

def initialize(root)
  @root = root
end

Instance Method Details

#can_delete?(path) ⇒ Boolean

Returns:

  • (Boolean)


236
237
238
# File 'lib/s3fsr.rb', line 236

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

#can_mkdir?(path) ⇒ Boolean

Returns:

  • (Boolean)


242
243
244
245
# File 'lib/s3fsr.rb', line 242

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

#can_rmdir?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


216
217
218
219
220
221
222
223
# File 'lib/s3fsr.rb', line 216

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



197
198
199
200
# File 'lib/s3fsr.rb', line 197

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

#delete(path) ⇒ Object



239
240
241
# File 'lib/s3fsr.rb', line 239

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

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/s3fsr.rb', line 201

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

#executable?(path) ⇒ Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/s3fsr.rb', line 207

def executable?(path)
  false
end

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


204
205
206
# File 'lib/s3fsr.rb', line 204

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

#mkdir(path) ⇒ Object



246
247
248
249
# File 'lib/s3fsr.rb', line 246

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



213
214
215
# File 'lib/s3fsr.rb', line 213

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

#rmdir(path) ⇒ Object



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

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

#size(path) ⇒ Object



210
211
212
# File 'lib/s3fsr.rb', line 210

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

#touch(path) ⇒ Object



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

def touch(path)
  get_object(path).touch
end

#write_to(path, data) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/s3fsr.rb', line 224

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