Class: FilePool::Pool
- Inherits:
-
Object
- Object
- FilePool::Pool
- Defined in:
- lib/simple_fs/file_pool.rb
Instance Method Summary collapse
- #delete(file_id) ⇒ Object
- #exist?(file_id) ⇒ Boolean
-
#initialize(pool_path) ⇒ Pool
constructor
A new instance of Pool.
- #puts(row_data) ⇒ Object
Constructor Details
#initialize(pool_path) ⇒ Pool
Returns a new instance of Pool.
6 7 8 9 |
# File 'lib/simple_fs/file_pool.rb', line 6 def initialize(pool_path) @pool_path = pool_path Dir.mkdir @pool_path unless Dir.exist? @pool_path end |
Instance Method Details
#delete(file_id) ⇒ Object
19 20 21 22 |
# File 'lib/simple_fs/file_pool.rb', line 19 def delete(file_id) file_path = File.join(@pool_path, file_id) File.unlink file_path if File.exist? file_path end |
#exist?(file_id) ⇒ Boolean
24 25 26 |
# File 'lib/simple_fs/file_pool.rb', line 24 def exist?(file_id) File.exist? File.join(@pool_path, file_id) end |
#puts(row_data) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/simple_fs/file_pool.rb', line 11 def puts(row_data) md5 = Digest::MD5.hexdigest(row_data) file_path = File.join(@pool_path, md5) File.open(file_path, 'w+').write(row_data) unless File.exist? file_path return md5 end |