experimental 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfb5dca3b1f51e5d7c288e7d61c91bdf770b7f8b
4
- data.tar.gz: ed36f94920862534016e94a3af96cb450abe69d3
3
+ metadata.gz: 1cbc23d7d4d559525acef4a4a02acc8f6129dddc
4
+ data.tar.gz: c90758e9493e4c965af09a9d0dc98c58d7fb4e53
5
5
  SHA512:
6
- metadata.gz: 8df805c7887851dfe3d08670355b6165b98ce5e6f4afd9d6a850cd61cc4ced9fe5ab5f0f72a12dee77031ad7e4d44eeb5d7a7746038b8ea6943a3c1a276b8c12
7
- data.tar.gz: 56bd5327657737cb6400291aafefa48704d6d90c286aea3bdb18c306e4f941cae57c07941326bbd15f02ff38617576860dc3ed3ec5892b9dfa7fefed8ad85452
6
+ metadata.gz: 8915404bdb3ce651853d2002598b113612561a87414062f97b8a3ef177beeac52cf6d203509c18d0af1ba2ba0506221a9468397f769362a647e9ebe3e1451e3e
7
+ data.tar.gz: 539a9ba09dc190a9983e1c558efff665f88759badd8e727a767154448f625e4b9d6d04c40597755c1cc44565f1a92ada9cc2ca897f8561ab3452b0622bfdd67f
@@ -42,7 +42,7 @@ module Experimental
42
42
  winning_bucket
43
43
  elsif Experimental.overrides.include?(subject, name)
44
44
  Experimental.overrides[subject, name]
45
- else
45
+ elsif started?
46
46
  bucket_number(subject)
47
47
  end
48
48
  end
@@ -63,6 +63,14 @@ module Experimental
63
63
  save
64
64
  end
65
65
 
66
+ def unstart
67
+ self.start_date = nil
68
+ self.end_date = nil
69
+ self.removed_at = nil
70
+ self.winning_bucket = nil
71
+ save
72
+ end
73
+
66
74
  def restart
67
75
  return unless ended?
68
76
 
@@ -90,12 +98,16 @@ module Experimental
90
98
  !removed_at.nil?
91
99
  end
92
100
 
101
+ def started?
102
+ start_date.present? && start_date <= Time.now
103
+ end
104
+
93
105
  def ended?
94
106
  !end_date.nil? && Time.now > end_date
95
107
  end
96
108
 
97
109
  def active?
98
- !removed? && !ended?
110
+ !removed? && started? && !ended?
99
111
  end
100
112
 
101
113
  def self.available
@@ -103,7 +115,8 @@ module Experimental
103
115
  end
104
116
 
105
117
  def self.active
106
- available.where(['end_date IS NULL OR ? <= end_date', Time.now])
118
+ now = Time.now
119
+ available.where('start_date < ? AND end_date IS NULL OR ? <= end_date', now, now)
107
120
  end
108
121
 
109
122
  def to_sql_formula(subject_table = "users")
@@ -14,10 +14,17 @@ module Experimental
14
14
  Experimental::Experiment.transaction do
15
15
  active = Experimental.experiment_data.map do |name, attributes|
16
16
  experiment = Experimental::Experiment.find_or_initialize_by_name(name)
17
- logger.info " * #{experiment.id ? 'updating' : 'creating'} #{name}"
17
+
18
+ unstarted = attributes.delete('unstarted')
18
19
  defaults = {'num_buckets' => nil, 'notes' => nil, 'population' => nil}
19
20
  experiment.assign_attributes(defaults.merge(attributes))
20
- experiment.start_date ||= Time.now
21
+ if unstarted
22
+ experiment.start_date = nil
23
+ else
24
+ experiment.start_date ||= Time.current
25
+ end
26
+
27
+ logger.info " * #{experiment.id ? 'updating' : 'creating'} #{name}"
21
28
  experiment.tap(&:save!)
22
29
  end
23
30
 
@@ -0,0 +1,11 @@
1
+ module Experimental
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ @app.call(env)
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Experimental
2
- VERSION = [0, 2, 5]
2
+ VERSION = [0, 3, 0]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: experimental
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HowAboutWe.com
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-03-27 00:00:00.000000000 Z
14
+ date: 2014-04-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -65,6 +65,7 @@ files:
65
65
  - lib/experimental/controller_actions.rb
66
66
  - lib/experimental/engine.rb
67
67
  - lib/experimental/loader.rb
68
+ - lib/experimental/middleware.rb
68
69
  - lib/experimental/overrides.rb
69
70
  - lib/experimental/railtie.rb
70
71
  - lib/experimental/rspec_helpers.rb
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  version: '0'
104
105
  requirements: []
105
106
  rubyforge_project:
106
- rubygems_version: 2.2.1
107
+ rubygems_version: 2.2.2
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: Adds support for database-backed AB tests in Rails apps