vignette 0.0.1pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/vignette/filter.rb +11 -0
- data/lib/vignette/object_extensions.rb +61 -0
- data/lib/vignette/version.rb +3 -0
- data/lib/vignette/vignette_errors.rb +4 -0
- data/lib/vignette.rb +46 -0
- data/vignette.gemspec +19 -0
- metadata +56 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Geoff Hayes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Vignette
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'vignette'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install vignette
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Haml::Filters::Vignette
|
2
|
+
include Haml::Filters::Base
|
3
|
+
|
4
|
+
# TODO: We need to find a way to disable caching
|
5
|
+
def render_with_options(text, options)
|
6
|
+
splitter = "\n"
|
7
|
+
splitter = '->' if text.include?('->')
|
8
|
+
lines = text.split splitter
|
9
|
+
lines.vignette
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module ObjectExtensions
|
2
|
+
|
3
|
+
# Extensions to the Array object
|
4
|
+
module ArrayExtensions
|
5
|
+
|
6
|
+
# Test will select a random object from the Array
|
7
|
+
def vignette(name=nil)
|
8
|
+
key = "vignette_#{name || hash}"
|
9
|
+
test_name = if name.blank?
|
10
|
+
if caller[0].include?('filter.rb')
|
11
|
+
caller[1].split(':in')[0].gsub(Rails.root.to_s,'') # Take the view name
|
12
|
+
else
|
13
|
+
caller[0].gsub(Rails.root.to_s,'') # Take everything but the Rails root portion
|
14
|
+
end
|
15
|
+
else
|
16
|
+
name
|
17
|
+
end
|
18
|
+
|
19
|
+
store = case Vignette.store
|
20
|
+
when :cookies
|
21
|
+
raise VignetteError::ConfigError, "Missing cookies configuration in Vignette. Must access Vignette in controller within around_filter." if Vignette.cookies.nil?
|
22
|
+
Vignette.cookies
|
23
|
+
when :session
|
24
|
+
raise VignetteError::ConfigError, "Missing session configuration in Vignette. Must access Vignette in controller within around_filter." if Vignette.session.nil?
|
25
|
+
# Rails.logger.debug [ 'Vignette::vignette', 'Session Sampling', key, Vignette.session[key], Vignette.session ]
|
26
|
+
Vignette.session
|
27
|
+
else
|
28
|
+
# Rails.logger.debug [ 'Vignette::vignette', 'Random Sampling' ]
|
29
|
+
{} # This is an empty storage
|
30
|
+
end
|
31
|
+
|
32
|
+
choice = store[key] ||= rand(length) # Store key into storage if not available
|
33
|
+
|
34
|
+
# We're going to track all tests in request
|
35
|
+
Vignette.request[:vignette] ||= {}
|
36
|
+
Vignette.request[:vignette][:tests] ||= {}
|
37
|
+
Vignette.request[:vignette][:tests][test_name] = choice
|
38
|
+
|
39
|
+
self[choice.to_i]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
module ActionControllerExtensions
|
45
|
+
|
46
|
+
def self.included(controller)
|
47
|
+
controller.around_filter(:init_vignette)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def init_vignette
|
53
|
+
Vignette.request_config(request, cookies, session)
|
54
|
+
yield
|
55
|
+
ensure
|
56
|
+
Vignette.clear_request # Clear request
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/lib/vignette.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "vignette/version"
|
2
|
+
require "vignette/object_extensions"
|
3
|
+
require "vignette/filter"
|
4
|
+
|
5
|
+
module Vignette
|
6
|
+
# Your code goes here...
|
7
|
+
mattr_accessor :store
|
8
|
+
mattr_accessor :request, :session, :cookies
|
9
|
+
|
10
|
+
# Initialization Code
|
11
|
+
|
12
|
+
# Defaults
|
13
|
+
Vignette.store = :session
|
14
|
+
|
15
|
+
# We're going to include ArrayExtensions
|
16
|
+
ActionController::Base.send(:include, ObjectExtensions::ActionControllerExtensions)
|
17
|
+
Array.send(:include, ObjectExtensions::ArrayExtensions)
|
18
|
+
|
19
|
+
# Member Functions
|
20
|
+
|
21
|
+
def self.init(opts={})
|
22
|
+
opts = {
|
23
|
+
store: :session
|
24
|
+
}.with_indifferent_access.merge(opts)
|
25
|
+
|
26
|
+
Vignette.store = opts[:store]
|
27
|
+
end
|
28
|
+
|
29
|
+
# Settings for configuations
|
30
|
+
def self.request_config(request, session, cookies)
|
31
|
+
Vignette.request = request
|
32
|
+
Vignette.session = session
|
33
|
+
Vignette.cookies = cookies
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.clear_request
|
37
|
+
Vignette.request = Vignette.session = Vignette.cookies = nil # clear items
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.tests
|
41
|
+
Vignette.request[:vignette] ||= {}
|
42
|
+
Vignette.request[:vignette][:tests] ||= {}
|
43
|
+
Vignette.request[:vignette][:tests]
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/vignette.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vignette/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "vignette"
|
8
|
+
gem.version = Vignette::VERSION
|
9
|
+
gem.authors = ["Geoff Hayes"]
|
10
|
+
gem.email = ["geoff@safeshepherd.com"]
|
11
|
+
gem.description = %q{Simple, effective A/b testing made easy.}
|
12
|
+
gem.summary = %q{With a few simple features, get A/b testing up in your application.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vignette
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1pre1
|
5
|
+
prerelease: 5
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Geoff Hayes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Simple, effective A/b testing made easy.
|
15
|
+
email:
|
16
|
+
- geoff@safeshepherd.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/vignette.rb
|
27
|
+
- lib/vignette/filter.rb
|
28
|
+
- lib/vignette/object_extensions.rb
|
29
|
+
- lib/vignette/version.rb
|
30
|
+
- lib/vignette/vignette_errors.rb
|
31
|
+
- vignette.gemspec
|
32
|
+
homepage: ''
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>'
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.3.1
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.25
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: With a few simple features, get A/b testing up in your application.
|
56
|
+
test_files: []
|