ft_gem 3.1.8 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ft_gem.rb +5 -0
- data/lib/ft_gem/controllers/helpers.rb +6 -11
- data/lib/ft_gem/services/beta_service.rb +21 -0
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c87e1b362c32c626bae277df5143edae9272ecd266f35385f1357f4e160afc56
|
4
|
+
data.tar.gz: 1b344e81360b00da689b46c280b9bd4e5c7e396f539dbe9164f9aaba75811d79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b130653d438520557292a204f73369a791c724a4e1063e947e63a77dc4853315bbb889049785313f0a9eabb8e8fa15570e74e523fad5178db2a6f141e0c9e24
|
7
|
+
data.tar.gz: 341027d3da3318695a647480268aa71925caab0d1dfabc82b21e778cb8ada8fd2efb27ee8b8d28c37838623858c8d55c199c04c196c9925efd6b9c5d57e2a942
|
data/lib/ft_gem.rb
CHANGED
@@ -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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
|
19
|
+
return true && whitelisted if FtGem::Services::BetaService.public_beta?(cookie: 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, toggles: nil, index: "")
|
60
|
-
user_id.present? && toggles.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.
|
4
|
+
version: 3.2.0
|
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-
|
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.
|
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: []
|