From 0df3f2dbe0bf8ce0714adb5d7c28da6af0fb3e92 Mon Sep 17 00:00:00 2001 From: Dmitry Davidov Date: Fri, 10 Jul 2020 16:34:11 +0300 Subject: [PATCH] Make configuration threadsafe [ch23375] (#73) * Make config threadsafe * Update README * Bump version --- README.md | 2 ++ lib/chartmogul.rb | 5 ++++- lib/chartmogul/version.rb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b7e808..2f35c04 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ ChartMogul.account_token = '' ChartMogul.secret_key = '' ``` +Configuration is threadsafe and applied only to the current thread. + Test your authentication: ```ruby ChartMogul::Ping.ping diff --git a/lib/chartmogul.rb b/lib/chartmogul.rb index 9a235c5..f7b160d 100644 --- a/lib/chartmogul.rb +++ b/lib/chartmogul.rb @@ -77,8 +77,11 @@ module ChartMogul class << self extend ConfigAttributes + CONFIG_THREAD_KEY = 'chartmogul_ruby.config' + def config - @config ||= ChartMogul::Configuration.new + Thread.current[CONFIG_THREAD_KEY] = ChartMogul::Configuration.new if Thread.current[CONFIG_THREAD_KEY].nil? + Thread.current[CONFIG_THREAD_KEY] end config_accessor :account_token diff --git a/lib/chartmogul/version.rb b/lib/chartmogul/version.rb index d067e10..f3f52fc 100644 --- a/lib/chartmogul/version.rb +++ b/lib/chartmogul/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ChartMogul - VERSION = '1.5.2' + VERSION = '1.6.0' end