Class: Harbor::FileStore::File
- Inherits:
-
Object
- Object
- Harbor::FileStore::File
- Defined in:
- lib/harbor/file_store/file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
-
#absolute_path ⇒ Object
Returns the full path to this file.
- #copy_on_read ⇒ Object
- #copy_on_write ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(store, path) ⇒ File
constructor
A new instance of File.
- #open(mode = "r") ⇒ Object
- #read(bytes = nil) ⇒ Object
- #size ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(store, path) ⇒ File
Returns a new instance of File.
7 8 9 10 11 12 |
# File 'lib/harbor/file_store/file.rb', line 7 def initialize(store, path) @store = store @path = path @pending_writes = [] end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/harbor/file_store/file.rb', line 5 def path @path end |
#store ⇒ Object
Returns the value of attribute store.
5 6 7 |
# File 'lib/harbor/file_store/file.rb', line 5 def store @store end |
Instance Method Details
#absolute_path ⇒ Object
Returns the full path to this file
90 91 92 |
# File 'lib/harbor/file_store/file.rb', line 90 def absolute_path (@store.root + @path).to_s end |
#copy_on_read ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/harbor/file_store/file.rb', line 27 def copy_on_read return @copy_on_read if @copy_on_read @copy_on_read = [] if store.[:copy_on_read] store.[:copy_on_read].each do |name| @copy_on_read << Harbor::FileStore[name].get(@path) end end @copy_on_read end |
#copy_on_write ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/harbor/file_store/file.rb', line 14 def copy_on_write return @copy_on_write if @copy_on_write @copy_on_write = [] if store.[:copy_on_write] store.[:copy_on_write].each do |name| @copy_on_write << Harbor::FileStore[name].get(@path) end end @copy_on_write end |
#exists? ⇒ Boolean
94 95 96 |
# File 'lib/harbor/file_store/file.rb', line 94 def exists? store.exists?(path) end |
#open(mode = "r") ⇒ Object
83 84 85 |
# File 'lib/harbor/file_store/file.rb', line 83 def open(mode = "r") @stream ||= store.open(path, mode) end |
#read(bytes = nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/harbor/file_store/file.rb', line 64 def read(bytes = nil) open("r") data = @stream.read(bytes) copy_on_read.each { |file| file.write(data) } unless bytes && data @stream.close @stream = nil end data end |
#size ⇒ Object
79 80 81 |
# File 'lib/harbor/file_store/file.rb', line 79 def size store.size(path) end |
#write(data) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/harbor/file_store/file.rb', line 40 def write(data) open("wb") copy_on_write.each do |file| if store.[:async_copy] @pending_writes << lambda { file.write(data) } else file.write(data) end end if data @stream.write(data) else @stream.close @stream = nil Thread.new { @pending_writes.each { |write| write.call } @pending_writes = [] } if store.[:async_copy] end end |