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 44 45 46 |
# File 'lib/abongo/sugar.rb', line 9 def ab_test(test_name, alternatives = nil, = {}) @choices ||= {} unless @choices[test_name] if (Abongo.[:enable_specification] && !params[test_name].nil?) @choices[test_name] = params[test_name] elsif (Abongo.[:enable_override_in_session] && !session[test_name].nil?) @choices[test_name] = session[test_name] elsif (Abongo.[:enable_selection] && !params[test_name].nil?) @choices[test_name] = Abongo.parse_alternatives(alternatives)[params[test_name].to_i] elsif (alternatives.nil?) begin @choices[test_name] = Abongo.flip(test_name, ) rescue if Abongo.[:failsafe] @choices[test_name] = true else raise end end else begin @choice[test_name] = Abongo.test(test_name, alternatives, ) rescue if Abongo.[:failsafe] @choices[test_name] = Abongo.parse_alternatives(alternatives).first else raise end end end end if block_given? yield(@choices[test_name]) else @choices[test_name] end end |
#abongo_mark_human ⇒ Object
Mark the user as a human.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/abongo/sugar.rb', line 61 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 |