ft_gem 3.1.6 → 3.1.12

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: 5ca0566dc7734cac585efc11741f71fdd293e4a924d207d0285d0555d4c63f34
4
- data.tar.gz: d88568950bac57aa06858fa31dc5b18f32179d938cf79c2f08045894984a3230
3
+ metadata.gz: c0e2da07f3d2533e273a4c2b299dc80c3fe95cf2d6dd30f84c2258a3a2ae6b22
4
+ data.tar.gz: 9eeca9dbd37d564fa512ed2cfec993af971911878ad46c54d4d573400a7e37a7
5
5
  SHA512:
6
- metadata.gz: 530936aef0568a373e8b59aba62ff94bbb11593ea3b6c96ac7a860fa4351f0d578a4fe439df584ccf8c61bbce872aa42df0233eb3e7cb377542ceb6bcea9171b
7
- data.tar.gz: 21a2c60a25d65c333fda8ed4cfe7eb6ea616cfd8490e9ff5acd46893f31adb0b6efc4f26b49e3afa79c4f01fdfe57d3737b31965c327b8c57457c070d4c1135c
6
+ metadata.gz: 4a55724fd18a65cb6d31d82bcb74951d36727bd9d7e7331ccfa624695724d346ff3b521afecec209f668becf8a59be0fb344f9cfd7ef655f80120928184c88d5
7
+ data.tar.gz: 637e41c423d27e01e4fe40fb810f307acbefacc4d00b58f24257a4502c3f2dc3bcc4a5382fff94a4e87e874b5c8cb9b783562fd22b912381589cc7bb60a3d236
@@ -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_beta(user_id: user_id)
18
- return true && whitelisted
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
@@ -53,12 +54,6 @@ module FtGem
53
54
  def api_feature_toggle_status(name:)
54
55
  FtGem::View::Helpers.status(name: name)
55
56
  end
56
-
57
- private
58
-
59
- def user_id_beta(user_id: nil)
60
- user_id.present? && toggles[index.to_i]['attributes']['status'] == "amber" && toggles[index.to_i]['attributes']['beta-users'].split(",").include?(user_id.to_s)
61
- end
62
57
  end
63
58
  end
64
59
  end
@@ -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[index.to_i].dig('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'] == "publicbeta"
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.6
4
+ version: 3.1.12
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: []