lib/verdict/experiment.rb in verdict-0.1.0 vs lib/verdict/experiment.rb in verdict-0.1.1

- old
+ new

@@ -12,16 +12,18 @@ def initialize(handle, options = {}, &block) @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 = options[:storage] || Verdict::Storage::MemoryStorage.new - @store_unqualified = options[:store_unqualified] - @segmenter = options[:segmenter] - @subject_type = options[:subject_type] + @qualifier = options[:qualifier] + @event_logger = options[:event_logger] || Verdict::EventLogger.new(Verdict.default_logger) + @subject_storage = options[:storage] || Verdict::Storage::MemoryStorage.new + @store_unqualified = options[:store_unqualified] + @segmenter = options[:segmenter] + @subject_type = options[:subject_type] + @disqualify_empty_identifier = options[:disqualify_empty_identifier] + instance_eval(&block) if block_given? end def subject_type(type = nil) return @subject_type if type.nil? @@ -81,10 +83,12 @@ def convert(subject, goal) identifier = retrieve_subject_identifier(subject) conversion = subject_conversion(identifier, goal) event_logger.log_conversion(conversion) conversion + rescue Verdict::EmptySubjectIdentifier + raise unless disqualify_empty_identifier? end def assign(subject, context = nil) identifier = retrieve_subject_identifier(subject) assignment = if store_unqualified? @@ -94,9 +98,19 @@ end store_assignment(assignment) rescue Verdict::StorageError subject_assignment(identifier, nil, nil) + rescue Verdict::EmptySubjectIdentifier + if disqualify_empty_identifier? + subject_assignment(identifier, nil, nil) + else + raise + end + end + + def disqualify_empty_identifier? + @disqualify_empty_identifier end def disqualify(subject) identifier = retrieve_subject_identifier(subject) store_assignment(subject_assignment(identifier, nil, nil))