Sha256: 6b5667e07ce3553fee0a5c169300e4a1699eec221adff107a80a4a09d2e3dd29

Contents?: true

Size: 693 Bytes

Versions: 13

Compression:

Stored size: 693 Bytes

Contents

module Adhoq
  module Storage
    class OnTheFly
      PREFIX = 'memory://adhoq-on-the-fly'

      attr_reader :identifier, :reports

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

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

      def direct_download?
        false
      end

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
adhoq-1.0.2 lib/adhoq/storage/on_the_fly.rb
adhoq-1.0.1 lib/adhoq/storage/on_the_fly.rb
adhoq-1.0.0 lib/adhoq/storage/on_the_fly.rb
adhoq-0.5.0 lib/adhoq/storage/on_the_fly.rb
adhoq-0.5.0.beta1 lib/adhoq/storage/on_the_fly.rb
adhoq-0.4.0 lib/adhoq/storage/on_the_fly.rb
adhoq-0.3.0 lib/adhoq/storage/on_the_fly.rb
adhoq-0.2.0 lib/adhoq/storage/on_the_fly.rb
adhoq-0.1.2 lib/adhoq/storage/on_the_fly.rb
adhoq-0.1.1 lib/adhoq/storage/on_the_fly.rb
adhoq-0.1.0 lib/adhoq/storage/on_the_fly.rb
adhoq-0.0.7 lib/adhoq/storage/on_the_fly.rb
adhoq-0.0.6 lib/adhoq/storage/on_the_fly.rb