experimental 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c3ca7d05e6f83ec23e057defc0da8e4d8b94b6f
4
- data.tar.gz: 19dd91453b0154b0d8cbc4b7c03e02860ba796e4
3
+ metadata.gz: 7663b9ae9da92b4a90b126980a4980dacb976431
4
+ data.tar.gz: 626412b747d825a405d5b0dacc93c30b0d24ac86
5
5
  SHA512:
6
- metadata.gz: 8f460e8ef869e751e103a936cf99c921293e700dd15387391ce4b84ed9207ecf49c472df59a02e29d38b471afa77ce708ff07d20722165585665e6a4d3dd6b79
7
- data.tar.gz: 24eeb5bec5c23fcbb3354804368d21fbad288b278942c82b191ead834b2e61b59bf5116443d8e03d5416a86021c2a38dcad013a6a7b2ab45b8fcc81c71b8833a
6
+ metadata.gz: 26702a568881b39baadf91a542f4ae76babc6ad41555c356b56953d588b61ae33627165a444c5a3ed1ae0c4686b4189d2b15139230d2a1f9542f30d98d86fcda
7
+ data.tar.gz: 71f434476e6ec9da639f358b924159c1995c46bd65835a2a8bfa57bdac8178aa275e8f418259c6d9423e869f69b1a70782102a8bcdcdd62b786d4139e383c89d
@@ -1,4 +1,4 @@
1
- # Experimental [![Build Status](https://travis-ci.org/howaboutwe/experimental.png?branch=master)](https://travis-ci.org/howaboutwe/experimental)
1
+ # Experimental [![Build Status](https://travis-ci.org/howaboutwe/experimental.png?branch=master)](https://travis-ci.org/howaboutwe/experimental) [![Code Climate](https://codeclimate.com/github/howaboutwe/experimental.png)](https://codeclimate.com/github/howaboutwe/experimental)
2
2
 
3
3
  Experimental is an Split testing framework for Rails.
4
4
  It was written with a few goals in mind:
@@ -18,8 +18,12 @@ module Experimental
18
18
  where(:removed_at => nil)
19
19
  end
20
20
 
21
+ def self.unstarted
22
+ where(start_date: nil)
23
+ end
24
+
21
25
  def self.in_progress
22
- where('removed_at is null and end_date is null').
26
+ where('start_date is not null and end_date is null and removed_at is null').
23
27
  order('start_date desc').
24
28
  order(:name)
25
29
  end
@@ -12,32 +12,55 @@ module Experimental
12
12
  logger.info "Synchronizing experiments..."
13
13
 
14
14
  Experimental::Experiment.transaction do
15
- active = Experimental.experiment_data.map do |name, attributes|
16
- experiment = Experimental::Experiment.where(name: name).first_or_initialize
17
-
18
- unstarted = attributes.delete('unstarted')
19
- defaults = {'num_buckets' => nil, 'notes' => nil, 'population' => nil}
20
- experiment.assign_attributes(defaults.merge(attributes))
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}"
28
- experiment.tap(&:save!)
29
- end
15
+ all_experiments = Experimental::Experiment.in_code
16
+ active_experiments = create_or_update_active_experiments
30
17
 
31
- scope = Experimental::Experiment.in_code
32
- scope = scope.where('id NOT IN (?)', active.map(&:id)) unless active.empty?
33
- scope.find_each do |experiment|
34
- next if experiment.admin?
35
- logger.info " * removing #{experiment.name}"
36
- experiment.remove
18
+ if active_experiments.present?
19
+ active_ids = active_experiments.map(&:id)
20
+ remove(all_experiments.where('id NOT IN (?)', active_ids))
21
+ else
22
+ remove(all_experiments)
37
23
  end
38
24
  end
39
25
 
40
26
  logger.info "Done."
41
27
  end
28
+
29
+ private
30
+
31
+ def create_or_update_active_experiments
32
+ Experimental.experiment_data.map do |name, attributes|
33
+ experiment = Experimental::Experiment.where(name: name).
34
+ first_or_initialize
35
+
36
+ reset_attributes(experiment, attributes)
37
+
38
+ logger.info " * #{experiment.id ? 'updating' : 'creating'} #{name}"
39
+
40
+ experiment.tap(&:save!)
41
+ end
42
+ end
43
+
44
+ def reset_attributes(experiment, attributes)
45
+ set_new_start_date(experiment, attributes)
46
+ defaults = {'num_buckets' => nil, 'notes' => nil, 'population' => nil}
47
+ experiment.assign_attributes(defaults.merge(attributes))
48
+ end
49
+
50
+ def remove(experiments)
51
+ experiments.find_each do |experiment|
52
+ next if experiment.admin?
53
+ logger.info " * removing #{experiment.name}"
54
+ experiment.remove
55
+ end
56
+ end
57
+
58
+ def set_new_start_date(experiment, attributes)
59
+ if (unstarted = attributes.delete('unstarted'))
60
+ experiment.start_date = nil
61
+ else
62
+ experiment.start_date ||= Time.current
63
+ end
64
+ end
42
65
  end
43
66
  end
@@ -1,5 +1,5 @@
1
1
  module Experimental
2
- VERSION = [0, 5, 0]
2
+ VERSION = [0, 6, 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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HowAboutWe.com
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-06-18 00:00:00.000000000 Z
15
+ date: 2015-01-15 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.2.2
103
+ rubygems_version: 2.4.5
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Adds support for database-backed AB tests in Rails apps