abongo 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,15 @@
1
- class Abongo
2
- @@VERSION = '0.0.1'
3
- def self.VERSION; @@VERSION; end
4
- @@MAJOR_VERSION = '0'
5
- def self.MAJOR_VERSION; @@MAJOR_VERSION; end
1
+ if defined? Rails
2
+ require 'abongo/sugar'
3
+ require 'abongo/view_helper'
4
+ require 'abongo/controller/dashboard'
5
+ ActionController::Base.send :include, Abongo::Sugar
6
+ ActionView::Base.send :include, Abongo::ViewHelper
7
+ end
6
8
 
9
+ require 'abongo/version'
10
+ require 'abongo/statistics'
11
+
12
+ class Abongo
7
13
  @@options ||= {}
8
14
  def self.options; @@options; end
9
15
  def self.options=(options); @@options = options; end
@@ -0,0 +1,52 @@
1
+ #This module exists entirely to save finger strain for programmers.
2
+ #It is designed to be included in your ApplicationController.
3
+ #
4
+ #See abongo.rb for descriptions of what these do.
5
+
6
+ class Abongo
7
+ module Sugar
8
+
9
+ def ab_test(test_name, alternatives = nil, options = {})
10
+ if (Abongo.options[:enable_specification] && !params[test_name].nil?)
11
+ choice = params[test_name]
12
+ elsif (Abongo.options[:enable_override_in_session] && !session[test_name].nil?)
13
+ choice = session[test_name]
14
+ elsif (Abongo.options[:enable_selection] && !params[test_name].nil?)
15
+ choice = alternatives[params[test_name].to_i]
16
+ elsif (alternatives.nil?)
17
+ choice = Abongo.flip(test_name, options)
18
+ else
19
+ choice = Abongo.test(test_name, alternatives, options)
20
+ end
21
+
22
+ if block_given?
23
+ yield(choice)
24
+ else
25
+ choice
26
+ end
27
+ end
28
+
29
+ def bongo!(test_name, options = {})
30
+ Abongo.bongo!(test_name, options)
31
+ end
32
+
33
+ #Mark the user as a human.
34
+ def abongo_mark_human
35
+ textual_result = "1"
36
+ begin
37
+ a = params[:a].to_i
38
+ b = params[:b].to_i
39
+ c = params[:c].to_i
40
+ if (request.method == :post && (a + b == c))
41
+ Abongo.human!
42
+ else
43
+ textual_result = "0"
44
+ end
45
+ 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.
46
+ textual_result = "0"
47
+ end
48
+ render :text => textual_result, :layout => false #Not actually used by browser
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,4 @@
1
+ class Abongo
2
+ VERSION = '1.0.0'
3
+ MAJOR_VERSION = '1'
4
+ end
@@ -0,0 +1,44 @@
1
+ #Gives you easy syntax to use ABongo in your views.
2
+
3
+ class Abongo
4
+ module ViewHelper
5
+
6
+ def ab_test(test_name, alternatives = nil, options = {}, &block)
7
+
8
+ if (Abongo.options[:enable_specification] && !params[test_name].nil?)
9
+ choice = params[test_name]
10
+ elsif (Abongo.options[:enable_override_in_session] && !session[test_name].nil?)
11
+ choice = session[test_name]
12
+ elsif (Abongo.options[:enable_selection] && !params[test_name].nil?)
13
+ choice = alternatives[params[test_name].to_i]
14
+ elsif (alternatives.nil?)
15
+ choice = Abongo.flip(test_name, options)
16
+ else
17
+ choice = Abongo.test(test_name, alternatives, options)
18
+ end
19
+
20
+ if block
21
+ content_tag = capture(choice, &block)
22
+ Rails::VERSION::MAJOR <= 2 and block_called_from_erb?(block) ? concat(content_tag) : content_tag
23
+ else
24
+ choice
25
+ end
26
+ end
27
+
28
+ def bongo!(test_name, options = {})
29
+ Abongo.bongo!(test_name, options)
30
+ end
31
+
32
+ #This causes an AJAX post against the URL. That URL should call Abongo.human!
33
+ #This guarantees that anyone calling Abongo.human! is capable of at least minimal Javascript execution, and thus is (probably) not a robot.
34
+ def include_humanizing_javascript(url = "/abongo_mark_human", style = :prototype)
35
+ script = nil
36
+ if (style == :prototype)
37
+ script = "var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=new Ajax.Request('#{url}', {parameters:{a: a, b: b, c: a+b}})"
38
+ elsif (style == :jquery)
39
+ script = "var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=jQuery.post('#{url}', {a: a, b: b, c: a+b})"
40
+ end
41
+ script.nil? ? "" : %Q|<script type="text/javascript">#{script}</script>|.html_safe
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -3,10 +3,10 @@ name: abongo
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
8
  - 0
8
- - 1
9
- version: 0.0.1
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Fairley
@@ -55,14 +55,13 @@ extra_rdoc_files: []
55
55
  files:
56
56
  - lib/abongo/controller/dashboard.rb
57
57
  - lib/abongo/statistics.rb
58
+ - lib/abongo/sugar.rb
59
+ - lib/abongo/version.rb
60
+ - lib/abongo/view_helper.rb
58
61
  - lib/abongo/views/dashboard/_experiment.html.erb
59
62
  - lib/abongo/views/dashboard/index.html.erb
60
63
  - lib/abongo.rb
61
64
  - lib/abongo.rb~
62
- - lib/abongo_sugar.rb
63
- - lib/abongo_view_helper.rb
64
- - rails/init.rb
65
- - rails/init.rb~
66
65
  - test/test_abongo.rb
67
66
  - test/test_abongo.rb~
68
67
  - MIT-LICENSE
@@ -1,51 +0,0 @@
1
- #This module exists entirely to save finger strain for programmers.
2
- #It is designed to be included in your ApplicationController.
3
- #
4
- #See abongo.rb for descriptions of what these do.
5
-
6
- module AbongoSugar
7
-
8
- def ab_test(test_name, alternatives = nil, options = {})
9
- if (Abongo.options[:enable_specification] && !params[test_name].nil?)
10
- choice = params[test_name]
11
- elsif (Abongo.options[:enable_override_in_session] && !session[test_name].nil?)
12
- choice = session[test_name]
13
- elsif (Abongo.options[:enable_selection] && !params[test_name].nil?)
14
- choice = alternatives[params[test_name].to_i]
15
- elsif (alternatives.nil?)
16
- choice = Abongo.flip(test_name, options)
17
- else
18
- choice = Abongo.test(test_name, alternatives, options)
19
- end
20
-
21
- if block_given?
22
- yield(choice)
23
- else
24
- choice
25
- end
26
- end
27
-
28
- def bongo!(test_name, options = {})
29
- Abongo.bongo!(test_name, options)
30
- end
31
-
32
- #Mark the user as a human.
33
- def abongo_mark_human
34
- textual_result = "1"
35
- begin
36
- a = params[:a].to_i
37
- b = params[:b].to_i
38
- c = params[:c].to_i
39
- if (request.method == :post && (a + b == c))
40
- Abongo.human!
41
- else
42
- textual_result = "0"
43
- end
44
- 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.
45
- textual_result = "0"
46
- end
47
- render :text => textual_result, :layout => false #Not actually used by browser
48
-
49
- end
50
-
51
- end
@@ -1,43 +0,0 @@
1
- #Gives you easy syntax to use ABongo in your views.
2
-
3
- module AbongoViewHelper
4
-
5
- def ab_test(test_name, alternatives = nil, options = {}, &block)
6
-
7
- if (Abongo.options[:enable_specification] && !params[test_name].nil?)
8
- choice = params[test_name]
9
- elsif (Abongo.options[:enable_override_in_session] && !session[test_name].nil?)
10
- choice = session[test_name]
11
- elsif (Abongo.options[:enable_selection] && !params[test_name].nil?)
12
- choice = alternatives[params[test_name].to_i]
13
- elsif (alternatives.nil?)
14
- choice = Abongo.flip(test_name, options)
15
- else
16
- choice = Abongo.test(test_name, alternatives, options)
17
- end
18
-
19
- if block
20
- content_tag = capture(choice, &block)
21
- Rails::VERSION::MAJOR <= 2 and block_called_from_erb?(block) ? concat(content_tag) : content_tag
22
- else
23
- choice
24
- end
25
- end
26
-
27
- def bongo!(test_name, options = {})
28
- Abongo.bongo!(test_name, options)
29
- end
30
-
31
- #This causes an AJAX post against the URL. That URL should call Abongo.human!
32
- #This guarantees that anyone calling Abongo.human! is capable of at least minimal Javascript execution, and thus is (probably) not a robot.
33
- def include_humanizing_javascript(url = "/abongo_mark_human", style = :prototype)
34
- script = nil
35
- if (style == :prototype)
36
- script = "var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=new Ajax.Request('#{url}', {parameters:{a: a, b: b, c: a+b}})"
37
- elsif (style == :jquery)
38
- script = "var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=jQuery.post('#{url}', {a: a, b: b, c: a+b})"
39
- end
40
- script.nil? ? "" : %Q|<script type="text/javascript">#{script}</script>|.html_safe
41
- end
42
-
43
- end
@@ -1,2 +0,0 @@
1
- ActionController::Base.send :include, AbongoSugar
2
- ActionView::Base.send :include, AbongoViewHelper
@@ -1,2 +0,0 @@
1
- ActionController::Base.send :include, AbongoSugar
2
- ActionView::Base.send :include, AbongoViewHelper