4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/deep_store/model/content_interface.rb', line 4
def self.included(base)
base.class_eval do
extend Forwardable
def_delegators :content, :read, :write, :rewind, :each, :puts, :close
def reload
@content = nil
end
def content
return @content if @content
self.content = persisted? ? __repository__.get(key).stream : Tempfile.new
end
def content=(stream)
ObjectSpace.define_finalizer(self, -> { stream.close })
@content = stream
end
end
end
|