Module: Abongo::Sugar
- Defined in:
- lib/abongo/sugar.rb
Instance Method Summary collapse
- #ab_test(test_name, alternatives = nil, options = {}) ⇒ Object
-
#abongo_mark_human ⇒ Object
Mark the user as a human.
- #bongo!(test_name, options = {}) ⇒ Object
Instance Method Details
#ab_test(test_name, alternatives = nil, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/abongo/sugar.rb', line 9 def ab_test(test_name, alternatives = nil, = {}) if (Abongo.[:enable_specification] && !params[test_name].nil?) choice = params[test_name] elsif (Abongo.[:enable_override_in_session] && !session[test_name].nil?) choice = session[test_name] elsif (Abongo.[:enable_selection] && !params[test_name].nil?) choice = Abongo.parse_alternatives(alternatives)[params[test_name].to_i] elsif (alternatives.nil?) begin choice = Abongo.flip(test_name, ) rescue if Abongo.[:failsafe] choice = true else raise end end else begin choice = Abongo.test(test_name, alternatives, ) rescue if Abongo.[:failsafe] choice = Abongo.parse_alternatives(alternatives).first else raise end end end if block_given? yield(choice) else choice end end |
#abongo_mark_human ⇒ Object
Mark the user as a human.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/abongo/sugar.rb', line 58 def abongo_mark_human textual_result = "1" begin a = params[:a].to_i b = params[:b].to_i c = params[:c].to_i if (request.method == :post && (a + b == c)) Abongo.human! else textual_result = "0" end rescue #If a bot doesn't pass a, b, or c, to_i will fail. This scarfs up the exception, to save it from polluting our logs. textual_result = "0" end render :text => textual_result, :layout => false #Not actually used by browser end |