lib/verdict/experiment.rb in verdict-0.2.1 vs lib/verdict/experiment.rb in verdict-0.3.0
- old
+ new
@@ -57,11 +57,11 @@
@qualifier = block
end
def storage(subject_storage = nil, options = {})
return @subject_storage if subject_storage.nil?
-
+
@store_unqualified = options[:store_unqualified] if options.has_key?(:store_unqualified)
@subject_storage = case subject_storage
when :memory; Verdict::Storage::MemoryStorage.new
when :none; Verdict::Storage::MockStorage.new
when Class; subject_storage.new
@@ -84,11 +84,11 @@
def group_handles
segmenter.groups.keys
end
- def subject_assignment(subject_identifier, group, originally_created_at, temporary = false)
+ def subject_assignment(subject_identifier, group, originally_created_at = nil, temporary = false)
Verdict::Assignment.new(self, subject_identifier, group, originally_created_at, temporary)
end
def subject_conversion(subject_identifier, goal, created_at = Time.now.utc)
Verdict::Conversion.new(self, subject_identifier, goal, created_at)
@@ -121,30 +121,44 @@
else
raise
end
end
- def disqualify_empty_identifier?
- @disqualify_empty_identifier
+ def assign_manually(subject, group)
+ identifier = retrieve_subject_identifier(subject)
+ assign_manually_by_identifier(identifier, group)
end
- def disqualify(subject)
- identifier = retrieve_subject_identifier(subject)
- store_assignment(subject_assignment(identifier, nil, nil))
+ def assign_manually_by_identifier(subject_identifier, group)
+ assignment = subject_assignment(subject_identifier, group)
+ if !assignment.qualified? && !store_unqualified?
+ raise Verdict::Error, "Unqualified subject assignments are not stored for this experiment, so manual disqualification is impossible. Consider setting :store_unqualified to true for this experiment."
+ end
+
+ store_assignment(assignment)
+ assignment
end
+ def disqualify_manually(subject)
+ assign_manually(subject, nil)
+ end
+
+ 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)
event_logger.log_assignment(assignment)
assignment
end
- def remove_subject(subject)
- remove_subject_identifier(retrieve_subject_identifier(subject))
+ def remove_subject_assignment(subject)
+ remove_subject_assignment_by_identifier(retrieve_subject_identifier(subject))
end
- def remove_subject_identifier(subject_identifier)
+ def remove_subject_assignment_by_identifier(subject_identifier)
@subject_storage.remove_assignment(self, subject_identifier)
end
def switch(subject, context = nil)
assign(subject, context).to_sym
@@ -198,9 +212,13 @@
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)
+ end
+
+ def disqualify_empty_identifier?
+ @disqualify_empty_identifier
end
protected
def default_options