Determinator Context
This is a gem to manage Determinator context objects.
It allows you to define the actors that will be determinated upon in a single place in the controller, where they can be tested; then, the ID to be determinated upon are decided either by pointing to an attribute in code, or with a structured setting in the feature itself.
Installation
Add this line to your application's Gemfile:
source "https://[email protected]/deliveroo/" do
gem 'determinator-context'
end
And then execute:
$ bundle
Usage
The simplest way to set up a context is to use the included helper in your controllers. For example:
class ApplicationController < ActionController::Base
include Determinator::Context::Helpers
determinator_actor(:request) do
Determinator::Models::Request.new(
uid: 'abc', customer: {guid: 'foo', sticky_guid: 'bar', session_guid: nil}
)
end
determinator_actor(:customer) do
next nil unless current_user.present?
Determinator::Models::Customer.new(
id: current_user.id,
email: current_user.email,
employee: current_user.employee
)
end
end
class MenuController < ApplicationController
include Determinator::Context::Helpers
determinator_actor(:restaurant) do
# If 'to_determinator' is a method on the model
# which returns the constructed object
restaurant.to_determinator
end
end
Then, if the feature has a structured_bucket
set, you can just use the determinator context to determinate:
determinator_context.which_variant('test_feature')
If the feature is not structured, or for some reason you want to override the structured bucket, you can do:
determinator_context.using('request.customer.guid').which_variant('test_feature')
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to GemFury.