Module: DeepStore::Model::ContentInterface

Defined in:
lib/deep_store/model/content_interface.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/deep_store/model/content_interface.rb', line 4

def self.included(base)
  base.class_eval do
    extend Forwardable

    attr_reader :sweeper

    def_delegators :content, :read, :write, :rewind, :each, :puts, :close, :unlink

    def reload
      @content = nil
    end

    def content
      return @content if @content
      self.content = persisted? ? __repository__.get(key).stream : Tempfile.new
    end

    def content=(stream)
      @content = stream
      @sweeper = Sweeper.register(self, stream)
    end

    def finalize
      sweeper&.finalize
    end
  end
end