Sha256: ccfb7a2e932c4a6e54150a64e2415189763e71659c43afece81a6627c57c70e4

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Verdict
  module Storage
    class MemoryStorage
      attr_reader :assignments, :start_timestamps

      def initialize
        @assignments = {}
        @start_timestamps = {}
      end

      def store_assignment(assignment)
        @assignments[assignment.experiment.handle] ||= {}
        @assignments[assignment.experiment.handle][assignment.subject_identifier] = assignment.returning
        true
      end

      def retrieve_assignment(experiment, subject_identifier)
        experiment_store = @assignments[experiment.handle] || {}
        experiment_store[subject_identifier]
      end

      def remove_assignment(experiment, subject_identifier)
        @assignments[assignment.experiment.handle] ||= {}
        @assignments[assignment.experiment.handle].delete(subject_identifier)
      end

      def clear_experiment(experiment)
        @assignments.delete(experiment.handle)
      end

      def retrieve_start_timestamp(experiment)
        @start_timestamps[experiment.handle]
      end

      def store_start_timestamp(experiment, timestamp)
        @start_timestamps[experiment.handle] = timestamp
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
verdict-0.2.1 lib/verdict/storage/memory_storage.rb