Class: ObjectPool::Pool
- Inherits:
-
Object
- Object
- ObjectPool::Pool
- Defined in:
- lib/object_pool.rb
Instance Method Summary collapse
- #delete(object_id) ⇒ Object
- #exist?(object_id) ⇒ Boolean
-
#get(object_id) ⇒ Object
get object object by object_id, read only.
-
#initialize(pool_path) ⇒ Pool
constructor
A new instance of Pool.
- #put(row_data) ⇒ Object
Constructor Details
#initialize(pool_path) ⇒ Pool
Returns a new instance of Pool.
8 9 10 11 |
# File 'lib/object_pool.rb', line 8 def initialize(pool_path) @pool_path = pool_path Dir.mkdir(@pool_path) unless Dir.exist?(@pool_path) end |
Instance Method Details
#delete(object_id) ⇒ Object
26 27 28 |
# File 'lib/object_pool.rb', line 26 def delete(object_id) File.unlink(get_object_path(object_id)) end |
#exist?(object_id) ⇒ Boolean
30 31 32 |
# File 'lib/object_pool.rb', line 30 def exist? object_id File.exist?(get_object_path(object_id)) end |
#get(object_id) ⇒ Object
get object object by object_id, read only
35 36 37 |
# File 'lib/object_pool.rb', line 35 def get(object_id) return File.open(get_object_path(object_id), "r") end |
#put(row_data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/object_pool.rb', line 13 def put(row_data) md5 = Digest::MD5.hexdigest(row_data) object_path = get_object_path(md5) object_dir = get_object_dir(md5) Dir.mkdir(object_dir) unless Dir.exist?(object_dir) File.open(object_path, 'w+') { |f| f.write(row_data) } return { :object_id => md5, :size => row_data.bytesize } end |