lib/verdict/experiment.rb in verdict-0.3.2 vs lib/verdict/experiment.rb in verdict-0.4.0
- old
+ new
@@ -1,10 +1,10 @@
class Verdict::Experiment
include Verdict::Metadata
- attr_reader :handle, :qualifier, :subject_storage, :event_logger
+ attr_reader :handle, :qualifier, :storage, :event_logger
def self.define(handle, *args, &block)
experiment = self.new(handle, *args, &block)
raise Verdict::ExperimentHandleNotUnique.new(experiment.handle) if Verdict.repository.has_key?(experiment.handle)
Verdict.repository[experiment.handle] = experiment
@@ -14,11 +14,11 @@
@handle = handle.to_s
options = default_options.merge(options)
@qualifier = options[:qualifier]
@event_logger = options[:event_logger] || Verdict::EventLogger.new(Verdict.default_logger)
- @subject_storage = storage(options[:storage] || :memory)
+ @storage = storage(options[:storage] || :memory)
@store_unqualified = options[:store_unqualified]
@segmenter = options[:segmenter]
@subject_type = options[:subject_type]
@disqualify_empty_identifier = options[:disqualify_empty_identifier]
@@ -55,29 +55,29 @@
def qualify(&block)
@qualifier = block
end
- def storage(subject_storage = nil, options = {})
- return @subject_storage if subject_storage.nil?
+ def storage(storage = nil, options = {})
+ return @storage if storage.nil?
@store_unqualified = options[:store_unqualified] if options.has_key?(:store_unqualified)
- @subject_storage = case subject_storage
+ @storage = case storage
when :memory; Verdict::Storage::MemoryStorage.new
when :none; Verdict::Storage::MockStorage.new
- when Class; subject_storage.new
- else subject_storage
+ when Class; storage.new
+ else storage
end
end
def segmenter
raise Verdict::Error, "No groups defined for experiment #{@handle.inspect}." if @segmenter.nil?
@segmenter
end
def started_at
- @started_at ||= @subject_storage.retrieve_start_timestamp(self)
+ @started_at ||= @storage.retrieve_start_timestamp(self)
end
def started?
!@started_at.nil?
end
@@ -145,21 +145,21 @@
def disqualify_manually_by_identifier(subject_identifier)
assign_manually_by_identifier(subject_identifier, nil)
end
def store_assignment(assignment)
- @subject_storage.store_assignment(assignment) if should_store_assignment?(assignment)
+ @storage.store_assignment(assignment) if should_store_assignment?(assignment)
event_logger.log_assignment(assignment)
assignment
end
def remove_subject_assignment(subject)
remove_subject_assignment_by_identifier(retrieve_subject_identifier(subject))
end
def remove_subject_assignment_by_identifier(subject_identifier)
- @subject_storage.remove_assignment(self, subject_identifier)
+ @storage.remove_assignment(self, subject_identifier)
end
def switch(subject, context = nil)
assign(subject, context).to_sym
end
@@ -170,14 +170,10 @@
def lookup_assignment_for_identifier(subject_identifier)
fetch_assignment(subject_identifier)
end
- def wrapup
- @subject_storage.clear_experiment(self)
- end
-
def retrieve_subject_identifier(subject)
identifier = subject_identifier(subject).to_s
raise Verdict::EmptySubjectIdentifier, "Subject resolved to an empty identifier!" if identifier.empty?
identifier
end
@@ -211,11 +207,11 @@
def fetch_subject(subject_identifier)
raise NotImplementedError, "Fetching subjects based in identifier is not implemented for eperiment @{handle.inspect}."
end
def fetch_assignment(subject_identifier)
- @subject_storage.retrieve_assignment(self, subject_identifier)
+ @storage.retrieve_assignment(self, subject_identifier)
end
def disqualify_empty_identifier?
@disqualify_empty_identifier
end
@@ -260,13 +256,13 @@
ensure_experiment_has_started
everybody_qualifies? || @qualifier.call(subject, context)
end
def set_start_timestamp
- @subject_storage.store_start_timestamp(self, started_now = Time.now.utc)
+ @storage.store_start_timestamp(self, started_now = Time.now.utc)
started_now
end
def ensure_experiment_has_started
- @started_at ||= @subject_storage.retrieve_start_timestamp(self) || set_start_timestamp
+ @started_at ||= @storage.retrieve_start_timestamp(self) || set_start_timestamp
end
end