lib/verdict/experiment.rb in verdict-0.1.1 vs lib/verdict/experiment.rb in verdict-0.2.0
- old
+ new
@@ -36,18 +36,24 @@
def group(handle)
segmenter.groups[handle.to_s]
end
- def groups(segmenter_class = Verdict::Segmenter::StaticPercentage, &block)
- return @segmenter.groups unless block_given?
+ def groups(segmenter_class = Verdict::FixedPercentageSegmenter, &block)
+ return segmenter.groups unless block_given?
@segmenter ||= segmenter_class.new(self)
@segmenter.instance_eval(&block)
@segmenter.verify!
return self
end
+ def rollout_percentage(percentage, rollout_group_name = :enabled)
+ groups(Verdict::RolloutSegmenter) do
+ group rollout_group_name, percentage
+ end
+ end
+
def qualify(&block)
@qualifier = block
end
def storage(subject_storage, options = {})
@@ -70,22 +76,23 @@
def group_handles
segmenter.groups.keys
end
- def subject_assignment(subject_identifier, group, originally_created_at = nil)
- Verdict::Assignment.new(self, subject_identifier, group, originally_created_at)
+ def subject_assignment(subject_identifier, group, originally_created_at, 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)
end
def convert(subject, goal)
identifier = retrieve_subject_identifier(subject)
conversion = subject_conversion(identifier, goal)
event_logger.log_conversion(conversion)
+ segmenter.conversion_feedback(identifier, subject, conversion)
conversion
rescue Verdict::EmptySubjectIdentifier
raise unless disqualify_empty_identifier?
end
@@ -192,28 +199,33 @@
def default_options
{}
end
def should_store_assignment?(assignment)
- !assignment.returning? && (store_unqualified? || assignment.qualified?)
+ assignment.permanent? && !assignment.returning? && (store_unqualified? || assignment.qualified?)
end
def assignment_with_unqualified_persistence(subject_identifier, subject, context)
- fetch_assignment(subject_identifier) || (
- subject_qualifies?(subject, context) ?
- subject_assignment(subject_identifier, @segmenter.assign(subject_identifier, subject, context), nil) :
- subject_assignment(subject_identifier, nil, nil)
- )
+ previous_assignment = fetch_assignment(subject_identifier)
+ return previous_assignment unless previous_assignment.nil?
+ if subject_qualifies?(subject, context)
+ group = segmenter.assign(subject_identifier, subject, context)
+ subject_assignment(subject_identifier, group, nil, group.nil?)
+ else
+ subject_assignment(subject_identifier, nil, nil)
+ end
end
def assignment_without_unqualified_persistence(subject_identifier, subject, context)
if subject_qualifies?(subject, context)
- fetch_assignment(subject_identifier) ||
- subject_assignment(subject_identifier, @segmenter.assign(subject_identifier, subject, context), nil)
+ previous_assignment = fetch_assignment(subject_identifier)
+ return previous_assignment unless previous_assignment.nil?
+ group = segmenter.assign(subject_identifier, subject, context)
+ subject_assignment(subject_identifier, group, nil, group.nil?)
else
subject_assignment(subject_identifier, nil, nil)
end
- end
+ end
def subject_identifier(subject)
subject.respond_to?(:id) ? subject.id : subject.to_s
end