lab_coat 0.1.5 → 0.1.6

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
  SHA256:
3
- metadata.gz: 19e5e50fffea78d509d6c9e9aa7454460250a80917689f0651003a62ba43c7d9
4
- data.tar.gz: e0f1a47e5cc78a8a3779dc17f53574b407b3191d870aadb28854ac58db567166
3
+ metadata.gz: '0628ef15e87d895d4df9ae050de05097b419938cacc86b057c1770599beecf50'
4
+ data.tar.gz: 17b42de37d69c9a9537c4af31b4a4be1c485d943d259a2eba3e72ddc7120d4d1
5
5
  SHA512:
6
- metadata.gz: da1dcbed4d24ae2ec3e68ab82aa7eb97d6314fff05aa7746d6e7075548c70faae9f11e804af9ef69bd43185ca7d9a9fbe7bf7748472cae629db1e9ea27893cd7
7
- data.tar.gz: 2f466dc529e11ae7967e93e72ff0b58d718e9b428891e913efe83b074ccb1e1d95ab50d1203e5e49e4a4c6ff8102145c630f422e742e4f736999f0dd6d495891
6
+ metadata.gz: 68a87b23225316873c1a0db120bc4e882bd981cee36192b767170944166f8975f4400397a9e517e2aa626f512632e25587ea5c528ea15eb7b6b4b3bf7724cee7
7
+ data.tar.gz: 7797d9da59a9cc808cdf6226c300864a0e67d40989efcadd87284b7efe8f1c2ad5a476d9994f3a1969d4bf0ed1f3894843188d5250d732413fe8970e091a56e1
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.1.7] - Unreleased
2
+
3
+ ## [0.1.6] - 2024-06-17
4
+ - [#1](https://github.com/omkarmoghe/lab_coat/issues/1)
5
+
1
6
  ## [0.1.5] - 2024-05-20
2
7
  - Adds `select_observation` to allow users to control which observation value is returned by the experiment. This helps with controlled rollout.
3
8
 
@@ -3,6 +3,8 @@
3
3
  module LabCoat
4
4
  # A base experiment class meant to be subclassed to define various experiments.
5
5
  class Experiment
6
+ OBSERVATIONS = %w[control candidate].freeze
7
+
6
8
  attr_reader :name, :context
7
9
 
8
10
  def initialize(name)
@@ -76,24 +78,33 @@ module LabCoat
76
78
  # It's not recommended to override this method.
77
79
  # @param context [Hash] Any data needed at runtime.
78
80
  # @return [Object] An `Observation` value.
79
- def run!(**context) # rubocop:disable Metrics/MethodLength
81
+ def run!(**context) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
80
82
  # Set the context for this run.
81
83
  @context = context
82
84
 
83
85
  # Run the control and exit early if the experiment is not enabled.
84
- control_obs = Observation.new("control", self) { control }
85
- raised(control_obs) if control_obs.raised?
86
- return control_obs.value unless enabled?
86
+ unless enabled?
87
+ control_obs = Observation.new("control", self) { control }
88
+ raised(control_obs) if control_obs.raised?
89
+ return control_obs.value
90
+ end
87
91
 
88
- # Run the candidate.
89
- candidate_obs = Observation.new("candidate", self) { candidate }
90
- raised(candidate_obs) if candidate_obs.raised?
92
+ # Otherwise run the control and candidate in random order.
93
+ observations = OBSERVATIONS.shuffle.map do |name|
94
+ Observation.new(name, self) { public_send(name) }.tap do |observation|
95
+ raised(observation) if observation.raised?
96
+ end
97
+ end
91
98
 
92
99
  # Compare and publish the results.
93
- result = Result.new(self, control_obs, candidate_obs)
100
+ result = if observations.first.name == "control"
101
+ Result.new(self, observations.first, observations.last)
102
+ else
103
+ Result.new(self, observations.last, observations.first)
104
+ end
94
105
  publish!(result)
95
106
 
96
- # Always return the control.
107
+ # Return the selected observations, control by default.
97
108
  select_observation(result).value.tap do
98
109
  # Reset the context for this run. Done here so that `select_observation` has access to the runtime context.
99
110
  @context = {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LabCoat
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab_coat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Omkar Moghe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-21 00:00:00.000000000 Z
11
+ date: 2024-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".rubocop.yml"
49
+ - ".ruby-version"
49
50
  - CHANGELOG.md
50
51
  - LICENSE.txt
51
52
  - README.md
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  - !ruby/object:Gem::Version
78
79
  version: '0'
79
80
  requirements: []
80
- rubygems_version: 3.4.1
81
+ rubygems_version: 3.4.19
81
82
  signing_key:
82
83
  specification_version: 4
83
84
  summary: A simple experiment library to safely test new code paths.