{"id":23248147,"url":"https://github.com/wizardone/black_and_white","last_synced_at":"2025-08-20T07:31:04.591Z","repository":{"id":56842935,"uuid":"60582511","full_name":"wizardone/black_and_white","owner":"wizardone","description":"A gem for A/B testing. Works with ActiveRecord and Mongoid","archived":false,"fork":false,"pushed_at":"2016-10-15T07:00:18.000Z","size":72,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-25T03:44:21.022Z","etag":null,"topics":["ab-testing","activerecord","mongoid","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wizardone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-07T04:37:14.000Z","updated_at":"2017-02-22T08:39:42.000Z","dependencies_parsed_at":"2022-08-29T12:40:59.542Z","dependency_job_id":null,"html_url":"https://github.com/wizardone/black_and_white","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fblack_and_white","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fblack_and_white/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fblack_and_white/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fblack_and_white/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wizardone","download_url":"https://codeload.github.com/wizardone/black_and_white/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230174907,"owners_count":18184928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ab-testing","activerecord","mongoid","rails","ruby"],"created_at":"2024-12-19T08:12:21.078Z","updated_at":"2024-12-19T08:12:21.753Z","avatar_url":"https://github.com/wizardone.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BlackAndWhite\n[![Build Status](https://travis-ci.org/wizardone/black_and_white.svg?branch=master)](https://travis-ci.org/wizardone/black_and_white)\n[![codecov](https://codecov.io/gh/wizardone/black_and_white/branch/master/graph/badge.svg)](https://codecov.io/gh/wizardone/black_and_white)\n\n\n### A/B Testing made easy\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'black_and_white', '~\u003e 0.2.0'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install black_and_white\n\n## Usage\nBlack And White is meant to work with Rails for the moment. It has\nsupport for ActiveRecord and Mongoid. In order to\nuse it first run:\n```ruby\nrails g black_and_white:config\n```\nthis will create a `black_and_white.rb` config file in\n`config/initializers` with some default values. The file looks like this:\n```ruby\nBlackAndWhite.configure do |config|\n  config.bw_class = 'User'\n  config.bw_class_table = :users\n  config.bw_main_table = :ab_tests\n  config.bw_join_table = :ab_tests_users\nend\n\nBlackAndWhite::Hooks.init\n```\nThe `Hooks` class requires all the necessary files for the detected\norm. If you are using `ActiveRecord` you need to generate the\ncorresponding migrations with:\n\n```ruby\nrails g black_and_white:migrations\n```\nReview them and then feel free to migrate. Keep in mind that they give\nyou only some very basic columns. You can add as much as you want and\nextend the logic\n\n### For ActiveRecord\nInclude the black_and_white module for activerecord interactions. The base class may have multiple a/b tests:\n```ruby\nclass User \u003c ActiveRecord::Base\n  include BlackAndWhite::ActiveRecord\nend\n```\n### For Mongoid\nInclude the black_and_white module for activerecord interactions. The base class may have multiple a/b tests:\n```ruby\nclass User\n  include Mongoid::Document\n  include BlackAndWhite::Mongoid\nend\n```\n\nTo create a new A/B test you can run:\n```ruby\nBlackAndWhite.create(name: 'My Test', active: true)\n```\nBy default all created tests are inactive.\nTo add existing users (or any other object) to the A/B Test you can call:\n```ruby\nuser.ab_participate!('My Test')\nuser.ab_tests.size\n=\u003e 1\nuser.ab_participates?('My Test')\n=\u003e true\n```\nYou can also supply an additional block which is evaluated:\n```ruby\nuser.ab_participate!('My Test') do |user|\n  user.admin? # returns true, user is added to the ab test\nend\n```\nA couple of additional options are supported as well:\n\n`join_inactive` =\u003e Join an a/b test, even if it is inactive\n```ruby\nuser.ab_participate!('My Inactive test', join_inactive: true)\n```\n`raise_on_missing` =\u003e raises a custom error message if the given a/b test does not exist\n```ruby\nuser.ab_participate!('My Inactive test', raise_on_missing: true)\n=\u003e AbTestError, \"no A/B Test with name My Inactive test exists or it is not active\"\n```\nA note for `Mongoid`: If you have `Mongoid.raise_not_found_error` this\nwill raise the generic mongoid error for not found documents.\n\nIf you added additional db colums or you want to add or extend more logic you can\nuse the `add` method which evaluates the given block in the scope of\nthe main `BlackAndWhite` module. That way you don't have to worry about\ncode location.\n```ruby\nBlackAndWhite.add(self) do\n  def my_new_method; end\n  private\n  attr_reader :my_property\nend\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/wizardone/black_and_white. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwizardone%2Fblack_and_white","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwizardone%2Fblack_and_white","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwizardone%2Fblack_and_white/lists"}