Class: SimpleFS::FS

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

Instance Method Summary collapse

Constructor Details

#initialize(fs_path) ⇒ FS

Returns a new instance of FS.



11
12
13
14
15
# File 'lib/simple_fs.rb', line 11

def initialize(fs_path)
	Dir.mkdir fs_path unless Dir.exist? fs_path
	@file_pool = FilePool::Pool.new File.join(fs_path, 'pool')
	@db = create_index_db File.join(fs_path, 'index.db')
end

Instance Method Details

#copy(old_path, new_path, optopns = {}) ⇒ Object



21
22
23
24
# File 'lib/simple_fs.rb', line 21

def copy(old_path, new_path, optopns = {})
	@old = @db[:index].where(:path => old_path).first
	@db[:index].insert(:path => new_path, :file_id => @old[:file_id])
end

#create(path, data, optopns = {}) ⇒ Object



30
31
32
33
# File 'lib/simple_fs.rb', line 30

def create(path, data, optopns = {})
	file_id = @file_pool.puts data
	@db[:index].insert(:path => path, :file_id => file_id)
end

#move(old_path, new_path, optopns = {}) ⇒ Object



17
18
19
# File 'lib/simple_fs.rb', line 17

def move(old_path, new_path, optopns = {})
	@db[:index].where(:path => old_path).update(:path => new_path)
end

#remove(path, optopns = {}) ⇒ Object



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

def remove(path, optopns = {})
	@db[:index].where(:path => path).delete
end