split-mongoid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in split-mongoid.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,15 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'bundler' do
5
+ watch('Gemfile')
6
+ # Uncomment next line if Gemfile contain `gemspec' command
7
+ # watch(/^.+\.gemspec/)
8
+ end
9
+
10
+ guard 'rspec' do
11
+ watch(%r{^spec/.+_spec\.rb$})
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch('spec/spec_helper.rb') { "spec" }
14
+ end
15
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Chris Winslett
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,55 @@
1
+ # Split::Mongoid
2
+
3
+ A Mongoid persistence layer for your A/B tests that use the Split Ruby
4
+ gem.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'split-mongoid'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install split-mongoid
19
+
20
+ ## Usage
21
+
22
+ Include in the Mongoid classes that will use the a/b tests:
23
+
24
+ ```ruby
25
+ class User
26
+ include Mongoid::Document
27
+ include Split::Mongoid
28
+ end
29
+ ```
30
+
31
+ Then, run your a/b tests:
32
+
33
+ ```ruby
34
+ user = User.new
35
+
36
+ user.ab_tests("favorite_superhero", "Superman", "Spiderman") do |hero|
37
+ puts hero
38
+ end
39
+ ```
40
+
41
+ Then, when finished, run:
42
+
43
+ ```ruby
44
+ user.finished("favorite_superhero")
45
+ ```
46
+
47
+ Reporting works exactly the same as the Split gem.
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module Split
2
+ module Mongoid
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,49 @@
1
+ require "split-mongoid/version"
2
+ require 'split'
3
+ require 'mongoid'
4
+
5
+ module Split
6
+ module Mongoid
7
+ class Adapter
8
+ def initialize(context)
9
+ @mongoid_object = context
10
+ @mongoid_object.split_tests ||= {}
11
+ end
12
+
13
+ def [](key)
14
+ @mongoid_object.split_tests[key]
15
+ end
16
+
17
+ def []=(key, value)
18
+ @mongoid_object.split_tests[key] = value
19
+ @mongoid_object.save
20
+ end
21
+
22
+ def delete(key)
23
+ @mongoid_object.split_tests.delete(key)
24
+ @mongoid_object.save
25
+ end
26
+
27
+ def keys
28
+ @mongoid_object.split_tests.keys
29
+ end
30
+
31
+ private
32
+ end
33
+
34
+ extend ActiveSupport::Concern
35
+ include Split::Helper
36
+
37
+ def is_robot?
38
+ defined?(request) ? super : false
39
+ end
40
+
41
+ def ab_user
42
+ @ab_user ||= Split::Mongoid::Adapter.new(self)
43
+ end
44
+
45
+ included do
46
+ field :split_tests, type: Hash, default: {}
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Split::Mongoid do
4
+
5
+ it "should be persistent" do
6
+ user = User.new
7
+
8
+ picked = user.ab_test("super_hero", "superman", "spiderman")
9
+
10
+ user.split_tests.should eq({"super_hero" => picked})
11
+ user.ab_test("super_hero", "superman", "spiderman").should eq(picked)
12
+ end
13
+
14
+ it "should finish" do
15
+ user = User.new
16
+ picked = user.ab_test("super_hero", "superman", "spiderman")
17
+ user.finished("super_hero")
18
+ end
19
+
20
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "../lib/split-mongoid"
2
+
3
+ require 'mongoid'
4
+ require 'split'
5
+
6
+ Mongoid::Config.sessions = {default: {uri: ENV['MONGOID_URL'] || "mongodb://127.0.0.1:27017/split-mongoid", options: {safe: true}}}
7
+
8
+ class User
9
+ include Mongoid::Document
10
+ include Split::Mongoid
11
+ end
12
+
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'split-mongoid/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "split-mongoid"
8
+ gem.version = Split::Mongoid::VERSION
9
+ gem.authors = ["Chris Winslett"]
10
+ gem.email = ["chris@mongohq.com"]
11
+ gem.description = %q{A Mongoid Persistence Layer for Split}
12
+ gem.summary = %q{Use Mongoid for your persistence layer when working with split}
13
+ gem.homepage = "http://github.com/mongohq/split-mongoid"
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
+
20
+ gem.add_dependency "mongoid", '> 3.0.0'
21
+ gem.add_dependency "split", '~> 0.5.0'
22
+ gem.add_dependency "activesupport", ">= 3.2.11"
23
+
24
+ gem.add_development_dependency "rspec"
25
+ gem.add_development_dependency "rspec-mocks"
26
+ gem.add_development_dependency "guard"
27
+ gem.add_development_dependency "guard-rspec"
28
+ gem.add_development_dependency "guard-bundler"
29
+ gem.add_development_dependency 'rb-fsevent', '~> 0.9.1'
30
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: split-mongoid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Winslett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongoid
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>'
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: split
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.5.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.5.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 3.2.11
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.11
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-mocks
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-bundler
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rb-fsevent
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 0.9.1
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 0.9.1
158
+ description: A Mongoid Persistence Layer for Split
159
+ email:
160
+ - chris@mongohq.com
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - .gitignore
166
+ - Gemfile
167
+ - Guardfile
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - lib/split-mongoid.rb
172
+ - lib/split-mongoid/version.rb
173
+ - spec/lib/split-mongid_spec.rb
174
+ - spec/spec_helper.rb
175
+ - split-mongoid.gemspec
176
+ homepage: http://github.com/mongohq/split-mongoid
177
+ licenses: []
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 1.8.23
197
+ signing_key:
198
+ specification_version: 3
199
+ summary: Use Mongoid for your persistence layer when working with split
200
+ test_files:
201
+ - spec/lib/split-mongid_spec.rb
202
+ - spec/spec_helper.rb