ft_gem 3.1.5 → 3.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f59d9f1f380088f670d59c8d4d1717a201c3fe01469b06869e0782c1ae10caf7
4
- data.tar.gz: c9f1ecb7b7e2138a8452d939d7560de5dcc5d1fa21a297ffab725d52b05fd4a3
3
+ metadata.gz: d64498a7f6859d6d51e064192b7812c5b3f3c1d5a7b4b09dfa2f08534fde4dbb
4
+ data.tar.gz: d1581653b1cd5fbe017ffac77557f68225b09a4d3264163f8de9b4299b258c8c
5
5
  SHA512:
6
- metadata.gz: 06e2149714a5b1d095275f98ff5e448c6f436b441a608e43b12ef7d82e0f9fbf687c3a4d7f9c504187d0ca0cddb1e89d78f8a475dd2533ea5c044d798210f3b7
7
- data.tar.gz: 54f5a746a6c7fb7ec73b89d37827a33d4aeefd6253c0bec17f0dcbf8e95d0e98d01b2712c7c3135b64a4433eed6b391d76415838b30ffdca0cddb9d41a38bc14
6
+ metadata.gz: dd3b8045267e02895e7b0941247ccf9c2de810cee6917b5669c75b420feef27140321c1882bf2f23e2ac279e1aafc90fb4c8272e150fd8fe1292251e43b269b7
7
+ data.tar.gz: 4eeb5c92e619c3305a9fc73fec4f2aa86222bae5da0e8f402458e160923e0b491f7fd592d7a68879c968530a0dbe396967d30b24df5ef8493055ac75495839ce
@@ -1,10 +1,15 @@
1
1
  require 'ft_gem/shared/ft_shared'
2
2
  require 'ft_gem/view/helpers'
3
+ require 'ft_gem/services/beta_service'
3
4
  module FtGem
4
5
  module Controllers
5
6
  autoload :Helpers, 'ft_gem/controllers/helpers'
6
7
  end
7
8
 
9
+ module Services
10
+ autoload :BetaService, 'ft_gem/services/beta_service'
11
+ end
12
+
8
13
  class Railtie < Rails::Railtie
9
14
  initializer 'ft_gem.view.helpers' do |_app|
10
15
  ActionView::Base.send :include, FtGem::View::Helpers
@@ -3,6 +3,7 @@ module FtGem
3
3
  module Helpers
4
4
  extend ActiveSupport::Concern
5
5
  TOGGLE_COOKIE_NAME = 'mnft'.freeze
6
+ PUBLICBETA_COOKIE_NAME = 'mnbeta'.freeze
6
7
  require 'base64'
7
8
 
8
9
  def feature_toggle_status(name:, user_id: nil, url: nil)
@@ -14,11 +15,11 @@ module FtGem
14
15
  client_percentage = calc_client_percentage(decoded_cookie: decoded_cookie, toggle_name: name)
15
16
  toggle_percentage = toggles[index.to_i]['attributes']['percentage']
16
17
  whitelisted = FtShared.new.whitelisted?(url: url, whitelist_urls: toggles[index.to_i]['attributes']['whitelist-urls'])
17
- if user_id.present? && toggles[index.to_i]['attributes']['status'] == "amber" && toggles[index.to_i]['attributes']['beta-users'] != "" && toggles[index.to_i]['attributes']['beta-users'].split(",").include?(user_id.to_s)
18
- return true
19
- else
20
- return client_percentage.to_i <= toggle_percentage.to_i && whitelisted
21
- end
18
+
19
+ return true && whitelisted if FtGem::Services::BetaService.public_beta(cookie: Base64.decode64(cookies[PUBLICBETA_COOKIE_NAME]),toggles: toggles, index: index)
20
+ return true && whitelisted if FtGem::Services::BetaService.private_beta(user_id: user_id, toggles: toggles, index: index)
21
+
22
+ return client_percentage.to_i <= toggle_percentage.to_i && whitelisted
22
23
  rescue StandardError => e
23
24
  Rails.logger.error "FtGem::feature_toggle_status error #{e.backtrace}"
24
25
  false
@@ -0,0 +1,21 @@
1
+ module FtGem
2
+ module Services
3
+ module BetaService
4
+ def self.private_beta?(user_id: nil, toggles: nil, index: "")
5
+ return false unless user_id.present?
6
+ return false unless toggles.present?
7
+
8
+ attributes = toggles.dig(index.to_i, 'attributes')
9
+
10
+ attributes['status'] == "privatebeta" && attributes['beta-users'].split(",").include?(user_id.to_s)
11
+ end
12
+
13
+ def self.public_beta?(cookie: "", toggles: nil, index: "")
14
+ return false unless toggles.present?
15
+
16
+ attributes = toggles.dig(index.to_i, 'attributes')
17
+ cookie == "true" && attributes['status'] == "privatebeta"
18
+ end
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ft_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murray Catto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-17 00:00:00.000000000 Z
11
+ date: 2020-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumsnet_jwt
@@ -38,20 +38,21 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description:
42
- email:
41
+ description:
42
+ email:
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - lib/ft_gem.rb
48
48
  - lib/ft_gem/controllers/helpers.rb
49
+ - lib/ft_gem/services/beta_service.rb
49
50
  - lib/ft_gem/shared/ft_shared.rb
50
51
  - lib/ft_gem/view/helpers.rb
51
- homepage:
52
+ homepage:
52
53
  licenses: []
53
54
  metadata: {}
54
- post_install_message:
55
+ post_install_message:
55
56
  rdoc_options: []
56
57
  require_paths:
57
58
  - lib
@@ -66,8 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
67
  - !ruby/object:Gem::Version
67
68
  version: '0'
68
69
  requirements: []
69
- rubygems_version: 3.0.8
70
- signing_key:
70
+ rubygems_version: 3.0.3
71
+ signing_key:
71
72
  specification_version: 4
72
73
  summary: Client side feature toggle
73
74
  test_files: []