Molasses

Ruby SDK#

A Ruby SDK for Molasses. It allows you to evaluate a user's status for a feature. It also helps simplify logging events for A/B testing.

Molasses uses polling to check if you have updated features. Once initialized, it takes microseconds to evaluate if a user is active.

Install#

1
gem install molasses
2
3
bundle add molasses

Usage#

Initialization#

Start by initializing the client with an APIKey. This begins the polling for any feature updates. The updates happen every 15 seconds.

ruby
1
require 'molasses'
2
3
client = Molasses::Client.new("test_api_key")

If you decide not to track analytics events (experiment started, experiment success) you can turn them off by setting the send_events field to false

ruby
1
client = Molasses::Client.new("test_api_key", false)

Check if feature is active#

You can call is_active with the key name and optionally a user's information. The id field is used to determine whether a user is part of a percentage of users. If you have other constraints based on user params you can pass those in the params field.

ruby
1
client.is_active("FOO_TEST", {
2
"id"=>"foo",
3
"params"=>{
4
"isBetaUser"=>"false",
5
"isScaredUser"=>"false"
6
}
7
})

You can check if a feature is active for a user who is anonymous by just calling isActive with the key. You won't be able to do percentage roll outs or track that user's behavior.

ruby
1
client.is_active("TEST_FEATURE_FOR_USER")

Experiments#

To track whether an experiment was successful you can call experiment_success. experiment_success takes the feature's name, any additional parameters for the event and the user.

ruby
1
client.experiment_success("GOOGLE_SSO",{
2
"version": "v2.3.0"
3
},{
4
"id"=>"foo",
5
"params"=>{
6
"isBetaUser"=>"false",
7
"isScaredUser"=>"false"
8
}
9
})

Example#

ruby
1
require 'molasses'
2
3
client = Molasses::Client.new("test_api_key")
4
5
if client.is_active('NEW_CHECKOUT') {
6
puts "we are a go"
7
else
8
puts "we are a no go"
9
end
10
foo_test = client.is_active("FOO_TEST", {
11
"id"=>"foo",
12
"params"=>{
13
"isBetaUser"=>"false",
14
"isScaredUser"=>"false"
15
}
16
})
17
if foo_test
18
puts "we are a go"
19
else
20
puts "we are a no go"
21
end
Ruby SDK