Sha256: 7147e73f12d0fa07582f07a0d3b9e86dccf846000bb16b17dd085b241bd828a7

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 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[experiment.handle] ||= {}
        @assignments[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

3 entries across 3 versions & 1 rubygems

Version Path
verdict-0.3.2 lib/verdict/storage/memory_storage.rb
verdict-0.3.1 lib/verdict/storage/memory_storage.rb
verdict-0.3.0 lib/verdict/storage/memory_storage.rb