Class: Adhoq::Storage::OnTheFly

Inherits:
Object
  • Object
show all
Defined in:
lib/adhoq/storage/on_the_fly.rb

Constant Summary collapse

PREFIX =
'memory://adhoq-on-the-fly'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id_base = Process.pid) ⇒ OnTheFly

Returns a new instance of OnTheFly.



8
9
10
11
# File 'lib/adhoq/storage/on_the_fly.rb', line 8

def initialize(id_base = Process.pid)
  @identifier = "#{PREFIX}-#{id_base}"
  @reports    = {}
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



6
7
8
# File 'lib/adhoq/storage/on_the_fly.rb', line 6

def identifier
  @identifier
end

#reportsObject (readonly)

Returns the value of attribute reports.



6
7
8
# File 'lib/adhoq/storage/on_the_fly.rb', line 6

def reports
  @reports
end

Instance Method Details

#direct_download?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/adhoq/storage/on_the_fly.rb', line 19

def direct_download?
  false
end

#get(identifier) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/adhoq/storage/on_the_fly.rb', line 23

def get(identifier)
  if item = @reports.delete(identifier)
    item.read.tap { item.close }
  else
    nil
  end
end

#store(suffix = nil, seed = Time.now, &block) ⇒ Object



13
14
15
16
17
# File 'lib/adhoq/storage/on_the_fly.rb', line 13

def store(suffix = nil, seed = Time.now, &block)
  Adhoq::Storage.with_new_identifier(suffix, seed) do |identifier|
    @reports[identifier] = yield.tap(&:rewind)
  end
end