ratel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format d
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ratel
2
2
 
3
- TODO: Write a gem description
3
+ A/B Testing on Rails
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,6 +20,16 @@ Or install it yourself as:
20
20
 
21
21
  TODO: Write usage instructions here
22
22
 
23
+ ### A/B Testing
24
+ Pattern A 50% / Pattern B 30% / Original 20%
25
+ <% screen_changes at: :cassette, to: { a: 50, b: 30 }, with: :reset do |g| %>
26
+ <dl>
27
+ <dt>Selected Group</dt>
28
+ <dd><%= g %></dd>
29
+ </dl>
30
+ <a href="javascript: <%= screen_conversion :cassette, :click, g %>">Conversion!</a>
31
+ <% end %>
32
+
23
33
  ## Contributing
24
34
 
25
35
  1. Fork it
@@ -27,3 +37,15 @@ TODO: Write usage instructions here
27
37
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
38
  4. Push to the branch (`git push origin my-new-feature`)
29
39
  5. Create new Pull Request
40
+
41
+ ## LICENSE
42
+ (The MIT License)
43
+
44
+ Copyright © 2013 yulii
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51
+
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Ratel</title>
6
+ <%= stylesheet_link_tag :all %>
7
+ <%= javascript_include_tag :defaults %>
8
+ <%= csrf_meta_tag %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
@@ -0,0 +1,8 @@
1
+ <p>TEST</p>
2
+ <% screen_changes at: :cassette, to: { a: 50, b: 30 }, with: :reset do |g| %>
3
+ <dl>
4
+ <dt>Selected Group</dt>
5
+ <dd><%= g %></dd>
6
+ </dl>
7
+ <a href="javascript: <%= screen_conversion :cassette, :click, g %>">Conversion!</a>
8
+ <% end %>
data/deploy_gem.sh ADDED
@@ -0,0 +1,31 @@
1
+ #!/bin/sh
2
+ LIB_NAME="ratel"
3
+ if [ $# -ne 1 ]
4
+ then
5
+ echo "invalid VERSION"
6
+ exit 1
7
+ fi
8
+ GEMSPEC="${LIB_NAME}.gemspec"
9
+ PKG_FILE="${LIB_NAME}-$1.gem"
10
+
11
+ echo "[RUN] rspec"
12
+ rspec
13
+ if [ $? -eq 1 ]
14
+ then
15
+ exit 1
16
+ fi
17
+ echo "[RUN] gem build ${GEMSPEC}"
18
+ gem build ${GEMSPEC}
19
+ if [ $? -eq 1 ]
20
+ then
21
+ exit 1
22
+ fi
23
+
24
+ echo "[RUN] mv ${PKG_FILE} pkg/"
25
+ mv ${PKG_FILE} ./pkg
26
+ echo "[RUN] gem push pkg/${PKG_FILE}"
27
+ gem push pkg/${PKG_FILE}
28
+
29
+ echo "[RUN] git tag -a version-$1"
30
+ git tag -a version-$1 -m ""
31
+ git push --tags
@@ -0,0 +1,33 @@
1
+ require 'active_support/configurable'
2
+
3
+ module Ratel
4
+ # Configures global settings for Ratel
5
+ # Ratel.configure do |config|
6
+ # config.tracking = :google_analytics
7
+ # end
8
+ def self.configure(&block)
9
+ yield @config ||= Ratel::Configuration.new
10
+ end
11
+
12
+ def self.config
13
+ @config
14
+ end
15
+
16
+ class Configuration #:nodoc:
17
+ include ActiveSupport::Configurable
18
+ config_accessor :tracking
19
+
20
+ def param_name
21
+ config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
22
+ end
23
+
24
+ # define param_name writer (copied from AS::Configurable)
25
+ writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
26
+ singleton_class.class_eval writer, __FILE__, line
27
+ class_eval writer, __FILE__, line
28
+ end
29
+
30
+ configure do |config|
31
+ config.tracking = :google_analytics
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ module Ratel
2
+ class Engine < ::Rails::Engine
3
+ initializer :ratel do |app|
4
+ ActionView::Base.send :include, Ratel::ActionViewExtension
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ module Ratel
2
+ module ActionViewExtension
3
+
4
+ def screen_changes *args, &block
5
+ options = args.extract_options!
6
+
7
+ s = :_screen_ticket
8
+
9
+ session[s] ||= {}
10
+ session[s] = {} if options[:with] == :reset
11
+
12
+ name = options[:at]
13
+ unless session[s].key? name
14
+ bar = 0
15
+ num = Time.now.usec % 100
16
+ options[:to].each do |k,v|
17
+ bar += v
18
+ if num < bar
19
+ session[s][name] = "_#{k}"
20
+ break
21
+ end
22
+ end
23
+ end
24
+ block.call session[s][name] || ''
25
+ end
26
+
27
+ def screen_conversion category, action, label
28
+ Ratel::Tracking::Event.push category, action, label
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ module Ratel
2
+ module Tracking
3
+ class Event
4
+
5
+ class << self
6
+ def push category, action, label
7
+ case Ratel.config.tracking
8
+ when :google_analytics
9
+ self.extend Ratel::Tracking::GoogleAnalytics
10
+ end
11
+ _push category, action, label
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Ratel
2
+ module Tracking
3
+ module GoogleAnalytics
4
+
5
+ def _push category, action, label, options = {}
6
+ s = "_gaq.push(['_trackEvent', '#{category}', '#{action}', '#{label}'"
7
+ s << ", #{options[:value]}" if options.key? :value
8
+ s << ", #{options[:noninteraction]}" if options.key? :noninteraction
9
+ s << "]);"
10
+ s.html_safe
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ require 'ratel/tracking/event'
2
+ require 'ratel/tracking/google_analytics'
data/lib/ratel/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ratel
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/ratel.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  require "ratel/version"
2
2
 
3
- require File.join(File.dirname(__FILE__),'ratel/helper.rb')
4
3
  module Ratel
5
- # Your code goes here...
4
+ end
5
+
6
+ require 'ratel/config'
7
+ require 'ratel/helper/action_view_extension.rb'
8
+ require 'ratel/tracking'
9
+
10
+ if defined? Rails
11
+ require 'ratel/engine'
6
12
  end
data/ratel.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["yuliinfo@gmail.com"]
11
11
  gem.description = %q{a/b testing module}
12
12
  gem.summary = %q{a/b testing module}
13
- gem.homepage = ""
13
+ gem.homepage = "https://github.com/yulii/ratel"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -0,0 +1,14 @@
1
+ # coding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ include Ratel::ActionViewExtension
5
+ describe Ratel::ActionViewExtension do
6
+
7
+ before do
8
+ visit "/"
9
+ puts page.html
10
+ end
11
+
12
+ subject { page }
13
+ it { should have_content "TEST" }
14
+ end
@@ -0,0 +1,28 @@
1
+ require 'action_controller/railtie'
2
+ require 'action_view/railtie'
3
+
4
+ # config
5
+ app = Class.new Rails::Application
6
+ app.config.active_support.deprecation = :log
7
+ app.config.secret_token = "e65e0140352e39703c113b0ce30335e8"
8
+ app.config.generators do |g|
9
+ g.template_engine :haml
10
+ end
11
+ app.initialize!
12
+
13
+ # routing
14
+ app.routes.draw do
15
+ get "/" =>"ratel#index" ,as: :index
16
+ end
17
+
18
+ # controllers
19
+ class ApplicationController < ActionController::Base ; end
20
+
21
+ class RatelController < ApplicationController
22
+ def index
23
+
24
+ end
25
+ end
26
+
27
+ # helpers
28
+ Object.const_set(:ApplicationHelper, Module.new)
@@ -0,0 +1,6 @@
1
+ # coding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Ratel do
5
+
6
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'rails_spec_app'
4
+ require 'ratel'
5
+
6
+ require 'capybara/rails'
7
+ RSpec.configure do |config|
8
+ config.mock_with :rspec
9
+ config.include Capybara::DSL
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -35,14 +35,28 @@ extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
37
  - .gitignore
38
+ - .rspec
38
39
  - Gemfile
39
40
  - LICENSE.txt
40
41
  - README.md
41
42
  - Rakefile
43
+ - app/views/layouts/application.html.erb
44
+ - app/views/ratel/index.html.erb
45
+ - deploy_gem.sh
42
46
  - lib/ratel.rb
47
+ - lib/ratel/config.rb
48
+ - lib/ratel/engine.rb
49
+ - lib/ratel/helper/action_view_extension.rb
50
+ - lib/ratel/tracking.rb
51
+ - lib/ratel/tracking/event.rb
52
+ - lib/ratel/tracking/google_analytics.rb
43
53
  - lib/ratel/version.rb
44
54
  - ratel.gemspec
45
- homepage: ''
55
+ - spec/helper/action_view_extension_spec.rb
56
+ - spec/rails_spec_app.rb
57
+ - spec/ratel_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: https://github.com/yulii/ratel
46
60
  licenses: []
47
61
  post_install_message:
48
62
  rdoc_options: []
@@ -66,4 +80,8 @@ rubygems_version: 1.8.24
66
80
  signing_key:
67
81
  specification_version: 3
68
82
  summary: a/b testing module
69
- test_files: []
83
+ test_files:
84
+ - spec/helper/action_view_extension_spec.rb
85
+ - spec/rails_spec_app.rb
86
+ - spec/ratel_spec.rb
87
+ - spec/spec_helper.rb