Sha256: 23c766206ef74a23f2937652bd7210702d06ad6b2f727bf1b578b96eac744c84
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
#encoding: utf-8 require "simple_fs/version" module SimpleFS require 'simple_fs/file_pool' require "sequel" class FS 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 def move(old_path, new_path, optopns = {}) @db[:index].where(:path => old_path).update(:path => new_path) end 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 def remove(path, optopns = {}) @db[:index].where(:path => path).delete end def create(path, data, optopns = {}) file_id = @file_pool.puts data @db[:index].insert(:path => path, :file_id => file_id) end private def create_index_db db_path db = Sequel.sqlite(db_path) unless db.table_exists? :index db.create_table :index do primary_key :id String :file_id String :path end end return db end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
simple_fs-0.0.1 | lib/simple_fs.rb |