Module: Abongo::Sugar

Defined in:
lib/abongo/sugar.rb

Instance Method Summary collapse

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, options = {})
  if (Abongo.options[:enable_specification] && !params[test_name].nil?)
    choice = params[test_name]
  elsif (Abongo.options[:enable_override_in_session] && !session[test_name].nil?)
    choice = session[test_name]
  elsif (Abongo.options[: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, options)
    rescue
      if Abongo.options[:failsafe]
        choice = true
      else
        raise
      end
    end
  else
    begin
      choice = Abongo.test(test_name, alternatives, options)
    rescue
      if Abongo.options[:failsafe]
        choice = Abongo.parse_alternatives(alternatives).first
      else
        raise
      end
    end
  end
  
  if block_given?
    yield(choice)
  else
    choice
  end
end

#abongo_mark_humanObject

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

#bongo!(test_name, options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/abongo/sugar.rb', line 45

def bongo!(test_name, options = {})
  begin
    Abongo.bongo!(test_name, options)
  rescue
    if Abongo.options[:failsafe]
      return
    else
      raise
    end
  end
end