Class: Persistable::MogileFSAdapter
- Inherits:
-
Object
- Object
- Persistable::MogileFSAdapter
- Defined in:
- lib/persistable/mogile_fs_adapter.rb
Instance Attribute Summary collapse
-
#mogile_fs_class ⇒ Object
readonly
Returns the value of attribute mogile_fs_class.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #delete(persistable) ⇒ Object
-
#initialize(options = {}) ⇒ MogileFSAdapter
constructor
A new instance of MogileFSAdapter.
- #read(persistable) ⇒ Object
- #write(persistable) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ MogileFSAdapter
Returns a new instance of MogileFSAdapter.
9 10 11 12 |
# File 'lib/persistable/mogile_fs_adapter.rb', line 9 def initialize( = {}) @options = @mogile_fs_class = [:class] end |
Instance Attribute Details
#mogile_fs_class ⇒ Object (readonly)
Returns the value of attribute mogile_fs_class.
6 7 8 |
# File 'lib/persistable/mogile_fs_adapter.rb', line 6 def mogile_fs_class @mogile_fs_class end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/persistable/mogile_fs_adapter.rb', line 6 def @options end |
Instance Method Details
#delete(persistable) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/persistable/mogile_fs_adapter.rb', line 38 def delete(persistable) hosts = [:tracker].is_a?(String) ? [[:tracker]] : [:tracker] connection = MogileFS::MogileFS.new(:domain => [:domain], :hosts => hosts, :timeout => [:timeout] ? [:timeout] : 10) begin status = connection.delete(persistable.persistence_key) rescue MogileFS::Backend::UnknownKeyError => e status = false ensure connection.backend.shutdown end status end |
#read(persistable) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/persistable/mogile_fs_adapter.rb', line 22 def read(persistable) hosts = [:tracker].is_a?(String) ? [[:tracker]] : [:tracker] connection = MogileFS::MogileFS.new(:domain => [:domain], :hosts => hosts, :timeout => [:timeout] ? [:timeout] : 10) begin if data = connection.get_file_data(persistable.persistence_key) persistable.persistence_data = StringIO.new(data) else persistable.persistence_data = nil end rescue MogileFS::Backend::UnknownKeyError, MogileFS::Backend::NoKeyError => e persistable.persistence_data = nil ensure connection.backend.shutdown end end |
#write(persistable) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/persistable/mogile_fs_adapter.rb', line 14 def write(persistable) hosts = [:tracker].is_a?(String) ? [[:tracker]] : [:tracker] connection = MogileFS::MogileFS.new(:domain => [:domain], :hosts => hosts, :timeout => [:timeout] ? [:timeout] : 10) status = connection.store_file(persistable.persistence_key, mogile_fs_class, persistable.persistence_data) connection.backend.shutdown status end |