module BlackAndWhite::ActiveRecord
Public Instance Methods
ab_participate!(test_name, **options) { |self| ... }
click to toggle source
# File lib/black_and_white/active_record.rb, line 15 def ab_participate!(test_name, **options, &block) @options = options if (@ab_test = fetch_ab_test(test_name)).present? conditions = true conditions = yield(self) if block_given? update_participant if conditions else missing_ab_test(test_name) end end
ab_participates?(test_name)
click to toggle source
# File lib/black_and_white/active_record.rb, line 26 def ab_participates?(test_name) ab_tests.detect { |ab_test| ab_test.name == test_name }.present? end
fetch_ab_test(name)
click to toggle source
# File lib/black_and_white/active_record.rb, line 43 def fetch_ab_test(name) query = { name: name } if options[:join_inactive] == false query.merge!(active: true) end BlackAndWhite::ActiveRecord::Test.find_by(query) end
missing_ab_test(test_name)
click to toggle source
# File lib/black_and_white/active_record.rb, line 36 def missing_ab_test(test_name) if options[:raise_on_missing] raise AbTestError, "no A/B Test with name #{test_name} exists or it is not active" end false end
update_participant()
click to toggle source
# File lib/black_and_white/active_record.rb, line 32 def update_participant ab_tests << ab_test end