ft_gem 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ft_gem.rb +6 -61
  3. metadata +1 -2
  4. data/lib/ft_helper.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95804ad56fcbe093c748e433da9e2dbd400a4d76c1d6a4a71b0fe1d0c6563db5
4
- data.tar.gz: ff8ecbf346c88a58ad7c072236ee6ef7428d104792d7f919ee6eb78918d155e7
3
+ metadata.gz: 3264692552401e623799002315e0cef3bf7a1ba66e6ebc5e50aa71c98be63ac2
4
+ data.tar.gz: 2fe783477992ae6dae407fdf69eced1edcfbaf910d623b9368418e3be6731854
5
5
  SHA512:
6
- metadata.gz: 503d4eb735804aee85150fac66d0fbf85d643868872a5d6c666458c4f112bb6e8b90b4866a5aac91da3219a4911ccd7a771fabffd9b6f15d802c3d8a5e9aeea4
7
- data.tar.gz: 73b0a43ed4a63023cf04036fe692a8ee6b007371c51483c2b22c6e3068698ce4f663798ddd47c7bf24b1294e2c488855a88e6cff1a5eb6fdbc6f36385e44abb2
6
+ metadata.gz: a8053934fde87274bda6f797068d40ecd882eefb1388ce61620000597de5e38fa5415d5a955468e41bbf012fafb6c2f0d34a748acdd63cef8465fe7ed1d9c04d
7
+ data.tar.gz: 9767220e4aafa0de34529c12b2557b60a83b466fde2e206096a44b42484a13ad0ee2fcdf78926336d7babdf74670587dc98df375cd5208fba7e09cb33216ca14
data/lib/ft_gem.rb CHANGED
@@ -1,67 +1,12 @@
1
+ require 'ft_gem/shared/ft_shared'
1
2
  module FtGem
2
- TOGGLE_COOKIE_NAME = 'mnft'.freeze
3
-
4
- def feature_toggle_status(name:)
5
- cookies[TOGGLE_COOKIE_NAME] = '' if cookies[TOGGLE_COOKIE_NAME].nil?
6
- add_feature_toggle(name: name) unless cookies[TOGGLE_COOKIE_NAME].include?("#{name} ")
7
- update_feature_toggle(name: name) if cookies[TOGGLE_COOKIE_NAME].include?("#{name} ")
8
- toggles = cookies[TOGGLE_COOKIE_NAME].split('|')
9
- index = toggles.index { |toggle| toggle.include?("#{name} ") }
10
- client_percentage = toggles[index].split(' ')[1]
11
- toggle_percentage = toggles[index].split(' ')[2]
12
- client_percentage.to_i <= toggle_percentage.to_i
13
- rescue StandardError
14
- Rails.logger.error "FtGem::feature_toggle_status error #{e.backtrace}"
15
- false
16
- end
17
-
18
- def add_feature_toggle(name:)
19
- data = Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
20
- JSON.parse(HTTP.headers(authentication_header).get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", params: { name: name }).body.to_s)
21
- end
22
- toggle_percentage = data['feature_toggle']['toggle_percentage']
23
- client_percentage = data['feature_toggle']['client_percentage']
24
- cookies[TOGGLE_COOKIE_NAME] = "#{cookies[TOGGLE_COOKIE_NAME]}|#{name} #{client_percentage} #{toggle_percentage}"
25
- rescue StandardError
26
- Rails.logger.error "FtGem::add_feature_toggle error #{e.backtrace}"
27
- nil
28
- end
29
-
30
- def update_feature_toggle(name:)
31
- data = Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
32
- JSON.parse(HTTP.headers(authentication_header).get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", params: { name: name }).body.to_s)
33
- end
34
- toggle_percentage = data['feature_toggle']['toggle_percentage']
35
- toggles = cookies[TOGGLE_COOKIE_NAME].split('|')
36
- index = toggles.index { |toggle| toggle.include?("#{name} ") }
37
- client_percentage = toggles[index].split(' ')[1]
38
- toggles[index] = "#{name} #{client_percentage} #{toggle_percentage}"
39
- cookies[TOGGLE_COOKIE_NAME] = toggles.join('|')
40
- rescue StandardError
41
- Rails.logger.error "FTApiGem::update_feature_toggle error #{e.backtrace}"
42
- nil
43
- end
44
-
45
- def api_feature_toggle_status(name:)
46
- toggle = api_fetch_feature_toggle(name: name)
47
- toggle['feature_toggle']['toggle_percentage'].to_i == 100
48
- rescue StandardError => e
49
- Rails.logger.error "FtGem::api_feature_toggle_status error #{e.backtrace}"
50
- false
3
+ module Controllers
4
+ autoload :Helpers, 'ft_gem/controllers/helpers'
51
5
  end
52
6
 
53
- def api_fetch_feature_toggle(name:)
54
- Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
55
- JSON.parse(HTTP.headers(authentication_header).get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", params: { name: name }).body.to_s)
7
+ class Railtie < Rails::Railtie
8
+ initializer 'body_class.helper' do |_app|
9
+ ActionView::Base.send :include, FtGem::View::Helper
56
10
  end
57
- rescue StandardError => e
58
- Rails.logger.error "FtGem::api_fetch_feature_toggle error #{e.backtrace}"
59
- nil
60
- end
61
-
62
- private
63
-
64
- def authentication_header
65
- { Authorization: "Bearer #{MumsnetJWT.tokenify}" }
66
11
  end
67
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ft_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murray Catto
@@ -31,7 +31,6 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/ft_gem.rb
34
- - lib/ft_helper.rb
35
34
  homepage:
36
35
  licenses: []
37
36
  metadata: {}
data/lib/ft_helper.rb DELETED
@@ -1,27 +0,0 @@
1
- module FtHelper
2
- class <<self
3
- def status(name:)
4
- toggle = fetch(name: name)
5
- toggle['feature_toggle']['toggle_percentage'].to_i == 100
6
- rescue StandardError => e
7
- Rails.logger.error "FtHelper::status error #{e.backtrace}"
8
- false
9
- end
10
-
11
- private
12
-
13
- def fetch(name:)
14
- Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
15
- JSON.parse(HTTP.headers(authentication_header).get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", params: { name: name }).body.to_s)
16
- end
17
- rescue StandardError => e
18
- Rails.logger.error "FtHelper::fetch error #{e.backtrace}"
19
- nil
20
- end
21
-
22
- def authentication_header
23
- { Authorization: "Bearer #{MumsnetJWT.tokenify}" }
24
- end
25
- end
26
- end
27
- ActionController::Base.helper FtHelper