From 1da51d6c1f5b2d9f61db5664aa7300261c69d1a4 Mon Sep 17 00:00:00 2001 From: "R. Arruda" Date: Thu, 28 Jun 2018 01:12:06 +0200 Subject: [PATCH] Fix Documentation - added information on how to use this gem with puma - added tags to the README.md for travis builds and coveralls. - added to gemspec information regarding required minimum ruby version. --- .travis.yml | 6 ++++- README.md | 60 ++++++++++++++++++++++++++++++++---------- spec/spec_helper.rb | 3 +++ unleash-client.gemspec | 3 +++ 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index b64d7705..9f37d7fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ sudo: false language: ruby rvm: - - 2.4.1 + - 2.2 + - 2.3 + - 2.4 + - 2.5 + - jruby before_install: gem install bundler -v 1.14.6 diff --git a/README.md b/README.md index 78921341..e3d4be84 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Unleash::Client +[![Build Status](https://travis-ci.org/Unleash/unleash-client-ruby.svg?branch=master)](https://travis-ci.org/Unleash/unleash-client-ruby) +[![Coverage Status](https://coveralls.io/repos/github/Unleash/unleash-client-ruby/badge.svg?branch=master)](https://coveralls.io/github/Unleash/unleash-client-ruby?branch=master) + Unleash client so you can roll out your features with confidence. Leverage the [Unleash Server](https://github.com/Unleash/unleash) for powerful feature toggling in your ruby/rails applications. @@ -9,7 +12,7 @@ Leverage the [Unleash Server](https://github.com/Unleash/unleash) for powerful f Add this line to your application's Gemfile: ```ruby -gem 'unleash', '~> 0.1.0' +gem 'unleash', '~> 0.1.1' ``` And then execute: @@ -22,15 +25,15 @@ Or install it yourself as: ## Configure -It is **required** to configure the `hostname` of the unleash server. +It is **required** to configure the `url` of the unleash server. Please substitute the sample `'http://unleash.herokuapp.com/api'` for the url of your own instance. It is **highly recommended** to configure `app_name` and the `instance_id`. For other options please see `lib/unleash/configuration.rb`. ```ruby -Unleash::Client.configure do |config| - config.hostname = 'host.domain' +Unleash.configure do |config| + config.url = 'http://unleash.herokuapp.com/api' config.app_name = 'my_ruby_app' end ``` @@ -38,7 +41,7 @@ end or instantiate the client with the valid configuration: ```ruby -UNLEASH = Unleash::Client.new(hostname: 'host.domain', app_name: 'my_ruby_app') +UNLEASH = Unleash::Client.new(url: 'http://unleash.herokuapp.com/api', app_name: 'my_ruby_app') ``` ## Usage in a plain Ruby Application @@ -47,7 +50,7 @@ UNLEASH = Unleash::Client.new(hostname: 'host.domain', app_name: 'my_ruby_app') require 'unleash' require 'unleash/context' -@unleash = Unleash::Client.new(hostname: 'host.domain', app_name: 'my_ruby_app') +@unleash = Unleash::Client.new(url: 'http://unleash.herokuapp.com/api', app_name: 'my_ruby_app') feature_name = "AwesomeFeature" unleash_context = Unleash::Context.new @@ -62,22 +65,41 @@ end ## Usage in a Rails Application -Note: known to not work currently with [puma](https://github.com/puma/puma). - #### Add Initializer Put in `config/initializers/unleash.rb`: ```ruby -Unleash::Client.configure do |config| - config.hostname = 'host.domain' - config.app_name = Rails.application.class.parent +Unleash.configure do |config| + config.url = 'http://unleash.herokuapp.com/api' + config.app_name = Rails.application.class.parent.to_s # config.instance_id = "#{Socket.gethostname}" end + +UNLEASH = Unleash::Client.new ``` For `config.instance_id` use a string with a unique identification for the running instance. For example: it could be the hostname, if you only run one App per host. Or the docker container id, if you are running in docker. If it is not set the client will generate an unique UUID for each execution. +#### Add Initializer if using [Puma](https://github.com/puma/puma) + +In `puma.rb` ensure that the unleash client is configured and instantiated as below, inside the `on_worker_boot` code block: + +```ruby +on_worker_boot do + # ... + + Unleash.configure do |config| + config.url = 'http://unleash.herokuapp.com/api' + config.app_name = Rails.application.class.parent.to_s + end + Rails.configuration.unleash = Unleash::Client.new +end +``` + +Instead of the configuration in `config/initializers/unleash.rb`. + + #### Set Unleash::Context Be sure to add the following method and callback in the application controller to have `@unleash_context` set for all requests: @@ -97,13 +119,23 @@ Add in `app/controllers/application_controller.rb`: end ``` +Or if you see better fit, only in the controllers that you will be using unleash. + #### Sample usage Then wherever in your application that you need a feature toggle, you can use: ```ruby if UNLEASH.is_enabled? "AwesomeFeature", @unleash_context - puts "enabled" + puts "AwesomeFeature is enabled" +end +``` + +or if client is set in `Rails.configuration.unleash`: + +```ruby +if Rails.configuration.unleash.is_enabled? "AwesomeFeature", @unleash_context + puts "AwesomeFeature is enabled" end ``` @@ -115,7 +147,7 @@ bundle exec examples/simple.rb ## Available Strategies -This client comes with these strategies out of the box: +This client comes with the all the required strategies out of the box: * ApplicationHostnameStrategy * DefaultStrategy @@ -133,7 +165,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run 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 [rubygems.org](https://rubygems.org). -See [TODO.md] for known limitations, and feature roadmap. +See (TODO.md) for known limitations, and feature roadmap. ## Contributing diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 50093c9d..64c38f07 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,9 @@ require "bundler/setup" require "unleash/client" +require 'coveralls' +Coveralls.wear! + RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = ".rspec_status" diff --git a/unleash-client.gemspec b/unleash-client.gemspec index eb28ebde..cb24275a 100644 --- a/unleash-client.gemspec +++ b/unleash-client.gemspec @@ -21,10 +21,13 @@ Gem::Specification.new do |spec| spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] + spec.required_ruby_version = "~> 2.2" spec.add_dependency "murmurhash3", "~> 0.1.6" spec.add_development_dependency "bundler", "~> 1.14" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" + spec.add_development_dependency "coveralls" + end