Class: Persistable::FSAdapter
- Inherits:
-
Object
- Object
- Persistable::FSAdapter
- Defined in:
- lib/persistable/fs_adapter.rb
Instance Attribute Summary collapse
-
#storage_location ⇒ Object
readonly
Returns the value of attribute storage_location.
Instance Method Summary collapse
- #delete(persistable) ⇒ Object
-
#initialize(options = {}) ⇒ FSAdapter
constructor
A new instance of FSAdapter.
- #read(persistable) ⇒ Object
- #write(persistable) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ FSAdapter
Returns a new instance of FSAdapter.
6 7 8 |
# File 'lib/persistable/fs_adapter.rb', line 6 def initialize( = {}) @storage_location = [:storage_location] || "/tmp" end |
Instance Attribute Details
#storage_location ⇒ Object (readonly)
Returns the value of attribute storage_location.
4 5 6 |
# File 'lib/persistable/fs_adapter.rb', line 4 def storage_location @storage_location end |
Instance Method Details
#delete(persistable) ⇒ Object
22 23 24 25 26 |
# File 'lib/persistable/fs_adapter.rb', line 22 def delete(persistable) if File.exists?(path = "#{storage_location}/#{persistable.persistence_key}") File.delete("#{storage_location}/#{persistable.persistence_key}") end end |
#read(persistable) ⇒ Object
16 17 18 19 20 |
# File 'lib/persistable/fs_adapter.rb', line 16 def read(persistable) if File.exists?(path = "#{storage_location}/#{persistable.persistence_key}") persistable.persistence_data = File.open(path) end end |
#write(persistable) ⇒ Object
10 11 12 13 14 |
# File 'lib/persistable/fs_adapter.rb', line 10 def write(persistable) File.open("#{storage_location}/#{persistable.persistence_key}", "w") do |file| file.write persistable.persistence_data.read end end |