flagsmith 3.2.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/Gemfile.lock +42 -56
- data/example/Gemfile +1 -1
- data/example/Gemfile.lock +3 -3
- data/flagsmith.gemspec +5 -5
- data/lib/flagsmith/sdk/config.rb +13 -2
- data/lib/flagsmith/sdk/models/flags.rb +14 -2
- data/lib/flagsmith/sdk/offline_handlers.rb +17 -0
- data/lib/flagsmith/version.rb +1 -1
- data/lib/flagsmith.rb +92 -33
- metadata +14 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f7e45006cc3caabc6941c7daaf58f339940cb1ea1fc3ec76be0a7897d84212fa
|
|
4
|
+
data.tar.gz: 32703828745194ea1befb791266e592e888c7fac888fd35c4cc6b6e9b6f3e204
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa77df821acafa8ccc9d0580845573b47fe0287c1937a7f8200d08532f559d77af1c41e6862a52a0ab90fec30cc020ea63068120aa95a95da41cff2b2a48e84d
|
|
7
|
+
data.tar.gz: 25f98c085b4b8253356fbc203e5605fa6ac53930e7ac8bbe7d2be1f5ba8dc8bf0374ca9a85b57bebafb08b9e57077dcc18637fca9b9d91a758ec404398de663a
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,90 +1,75 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
flagsmith (
|
|
5
|
-
faraday
|
|
4
|
+
flagsmith (4.0.0)
|
|
5
|
+
faraday (>= 2.0.1)
|
|
6
6
|
faraday-retry
|
|
7
|
-
faraday_middleware
|
|
8
7
|
semantic
|
|
9
8
|
|
|
10
9
|
GEM
|
|
11
10
|
remote: https://rubygems.org/
|
|
12
11
|
specs:
|
|
13
12
|
ast (2.4.2)
|
|
13
|
+
byebug (11.1.3)
|
|
14
14
|
coderay (1.1.3)
|
|
15
|
-
diff-lcs (1.
|
|
16
|
-
faraday (
|
|
17
|
-
faraday-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
faraday
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
faraday-patron (~> 1.0)
|
|
25
|
-
faraday-rack (~> 1.0)
|
|
26
|
-
faraday-retry (~> 1.0)
|
|
27
|
-
ruby2_keywords (>= 0.0.4)
|
|
28
|
-
faraday-em_http (1.0.0)
|
|
29
|
-
faraday-em_synchrony (1.0.0)
|
|
30
|
-
faraday-excon (1.1.0)
|
|
31
|
-
faraday-httpclient (1.0.1)
|
|
32
|
-
faraday-multipart (1.0.4)
|
|
33
|
-
multipart-post (~> 2)
|
|
34
|
-
faraday-net_http (1.0.1)
|
|
35
|
-
faraday-net_http_persistent (1.2.0)
|
|
36
|
-
faraday-patron (1.0.0)
|
|
37
|
-
faraday-rack (1.0.0)
|
|
38
|
-
faraday-retry (1.0.3)
|
|
39
|
-
faraday_middleware (1.2.0)
|
|
40
|
-
faraday (~> 1.0)
|
|
41
|
-
gem-release (2.2.0)
|
|
42
|
-
json (2.6.3)
|
|
15
|
+
diff-lcs (1.5.0)
|
|
16
|
+
faraday (2.9.0)
|
|
17
|
+
faraday-net_http (>= 2.0, < 3.2)
|
|
18
|
+
faraday-net_http (3.1.0)
|
|
19
|
+
net-http
|
|
20
|
+
faraday-retry (2.2.0)
|
|
21
|
+
faraday (~> 2.0)
|
|
22
|
+
gem-release (2.2.2)
|
|
23
|
+
json (2.7.1)
|
|
43
24
|
language_server-protocol (3.17.0.3)
|
|
44
25
|
method_source (1.0.0)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
net-http (0.4.1)
|
|
27
|
+
uri
|
|
28
|
+
parallel (1.24.0)
|
|
29
|
+
parser (3.3.0.4)
|
|
48
30
|
ast (~> 2.4.1)
|
|
49
31
|
racc
|
|
50
|
-
pry (0.14.
|
|
32
|
+
pry (0.14.2)
|
|
51
33
|
coderay (~> 1.1)
|
|
52
34
|
method_source (~> 1.0)
|
|
53
|
-
|
|
35
|
+
pry-byebug (3.10.1)
|
|
36
|
+
byebug (~> 11.0)
|
|
37
|
+
pry (>= 0.13, < 0.15)
|
|
38
|
+
racc (1.7.3)
|
|
54
39
|
rainbow (3.1.1)
|
|
55
|
-
rake (13.0
|
|
56
|
-
regexp_parser (2.
|
|
57
|
-
rexml (3.2.
|
|
58
|
-
rspec (3.
|
|
59
|
-
rspec-core (~> 3.
|
|
60
|
-
rspec-expectations (~> 3.
|
|
61
|
-
rspec-mocks (~> 3.
|
|
62
|
-
rspec-core (3.
|
|
63
|
-
rspec-support (~> 3.
|
|
64
|
-
rspec-expectations (3.
|
|
40
|
+
rake (13.1.0)
|
|
41
|
+
regexp_parser (2.9.0)
|
|
42
|
+
rexml (3.2.6)
|
|
43
|
+
rspec (3.12.0)
|
|
44
|
+
rspec-core (~> 3.12.0)
|
|
45
|
+
rspec-expectations (~> 3.12.0)
|
|
46
|
+
rspec-mocks (~> 3.12.0)
|
|
47
|
+
rspec-core (3.12.2)
|
|
48
|
+
rspec-support (~> 3.12.0)
|
|
49
|
+
rspec-expectations (3.12.3)
|
|
65
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
66
|
-
rspec-support (~> 3.
|
|
67
|
-
rspec-mocks (3.
|
|
51
|
+
rspec-support (~> 3.12.0)
|
|
52
|
+
rspec-mocks (3.12.6)
|
|
68
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
69
|
-
rspec-support (~> 3.
|
|
70
|
-
rspec-support (3.
|
|
71
|
-
rubocop (1.
|
|
54
|
+
rspec-support (~> 3.12.0)
|
|
55
|
+
rspec-support (3.12.1)
|
|
56
|
+
rubocop (1.60.0)
|
|
72
57
|
json (~> 2.3)
|
|
73
58
|
language_server-protocol (>= 3.17.0)
|
|
74
59
|
parallel (~> 1.10)
|
|
75
|
-
parser (>= 3.
|
|
60
|
+
parser (>= 3.3.0.2)
|
|
76
61
|
rainbow (>= 2.2.2, < 4.0)
|
|
77
62
|
regexp_parser (>= 1.8, < 3.0)
|
|
78
63
|
rexml (>= 3.2.5, < 4.0)
|
|
79
|
-
rubocop-ast (>= 1.
|
|
64
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
80
65
|
ruby-progressbar (~> 1.7)
|
|
81
66
|
unicode-display_width (>= 2.4.0, < 3.0)
|
|
82
|
-
rubocop-ast (1.
|
|
67
|
+
rubocop-ast (1.30.0)
|
|
83
68
|
parser (>= 3.2.1.0)
|
|
84
69
|
ruby-progressbar (1.13.0)
|
|
85
|
-
ruby2_keywords (0.0.5)
|
|
86
70
|
semantic (1.6.1)
|
|
87
|
-
unicode-display_width (2.
|
|
71
|
+
unicode-display_width (2.5.0)
|
|
72
|
+
uri (0.13.0)
|
|
88
73
|
|
|
89
74
|
PLATFORMS
|
|
90
75
|
ruby
|
|
@@ -94,6 +79,7 @@ DEPENDENCIES
|
|
|
94
79
|
flagsmith!
|
|
95
80
|
gem-release
|
|
96
81
|
pry
|
|
82
|
+
pry-byebug
|
|
97
83
|
rake
|
|
98
84
|
rspec
|
|
99
85
|
rubocop
|
data/example/Gemfile
CHANGED
data/example/Gemfile.lock
CHANGED
|
@@ -161,7 +161,7 @@ GEM
|
|
|
161
161
|
method_source (1.0.0)
|
|
162
162
|
mini_mime (1.1.2)
|
|
163
163
|
multipart-post (2.3.0)
|
|
164
|
-
nio4r (2.5.
|
|
164
|
+
nio4r (2.5.9)
|
|
165
165
|
nokogiri (1.14.3-arm64-darwin)
|
|
166
166
|
racc (~> 1.4)
|
|
167
167
|
nokogiri (1.14.3-x86_64-linux)
|
|
@@ -173,7 +173,7 @@ GEM
|
|
|
173
173
|
coderay (~> 1.1)
|
|
174
174
|
method_source (~> 1.0)
|
|
175
175
|
public_suffix (5.0.1)
|
|
176
|
-
puma (
|
|
176
|
+
puma (6.3.1)
|
|
177
177
|
nio4r (~> 2.0)
|
|
178
178
|
racc (1.6.2)
|
|
179
179
|
rack (2.2.7)
|
|
@@ -262,7 +262,7 @@ DEPENDENCIES
|
|
|
262
262
|
hanami-model (~> 1.3)
|
|
263
263
|
hanami-webconsole
|
|
264
264
|
pry
|
|
265
|
-
puma (~>
|
|
265
|
+
puma (~> 6.3)
|
|
266
266
|
rake
|
|
267
267
|
rspec
|
|
268
268
|
rubocop
|
data/flagsmith.gemspec
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
require File.expand_path('lib/flagsmith/version', __dir__)
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
|
-
spec.required_ruby_version = '>=
|
|
6
|
+
spec.required_ruby_version = '>= 3.0.0'
|
|
7
7
|
spec.name = 'flagsmith'
|
|
8
8
|
spec.version = Flagsmith::VERSION
|
|
9
|
-
spec.authors = ['Tom Stuart', 'Brian Moelk']
|
|
10
|
-
spec.email = ['tom@solidstategroup.com', 'bmoelk@gmail.com']
|
|
9
|
+
spec.authors = ['Tom Stuart', 'Brian Moelk', 'Zach Aysan']
|
|
10
|
+
spec.email = ['tom@solidstategroup.com', 'bmoelk@gmail.com', 'zachaysan@gmail.com']
|
|
11
11
|
# Specify which files should be added to the gem when it is released.
|
|
12
12
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
13
13
|
spec.files = Dir.chdir(__dir__) do
|
|
@@ -27,12 +27,12 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
spec.add_development_dependency 'bundler'
|
|
28
28
|
spec.add_development_dependency 'gem-release'
|
|
29
29
|
spec.add_development_dependency 'pry'
|
|
30
|
+
spec.add_development_dependency 'pry-byebug'
|
|
30
31
|
spec.add_development_dependency 'rake'
|
|
31
32
|
spec.add_development_dependency 'rspec'
|
|
32
33
|
spec.add_development_dependency 'rubocop'
|
|
33
34
|
|
|
34
|
-
spec.add_dependency 'faraday'
|
|
35
|
-
spec.add_dependency 'faraday_middleware'
|
|
35
|
+
spec.add_dependency 'faraday', '>= 2.0.1'
|
|
36
36
|
spec.add_dependency 'faraday-retry'
|
|
37
37
|
spec.add_dependency 'semantic'
|
|
38
38
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
data/lib/flagsmith/sdk/config.rb
CHANGED
|
@@ -6,7 +6,8 @@ module Flagsmith
|
|
|
6
6
|
DEFAULT_API_URL = 'https://edge.api.flagsmith.com/api/v1/'
|
|
7
7
|
OPTIONS = %i[
|
|
8
8
|
environment_key api_url custom_headers request_timeout_seconds enable_local_evaluation
|
|
9
|
-
environment_refresh_interval_seconds retries enable_analytics default_flag_handler
|
|
9
|
+
environment_refresh_interval_seconds retries enable_analytics default_flag_handler
|
|
10
|
+
offline_mode offline_handler logger
|
|
10
11
|
].freeze
|
|
11
12
|
|
|
12
13
|
# Available Configs
|
|
@@ -31,8 +32,12 @@ module Flagsmith
|
|
|
31
32
|
# API to power flag analytics charts
|
|
32
33
|
# +default_flag_handler+ - ruby block which will be used in the case where
|
|
33
34
|
# flags cannot be retrieved from the API or
|
|
34
|
-
# a non
|
|
35
|
+
# a non-existent feature is requested.
|
|
35
36
|
# The searched feature#name will be passed to the block as an argument.
|
|
37
|
+
# +offline_mode+ - if enabled, uses a locally provided file and
|
|
38
|
+
# bypasses requests to the api.
|
|
39
|
+
# +offline_handler+ - A file object that contains a JSON serialization of
|
|
40
|
+
# the entire environment, project, flags, etc.
|
|
36
41
|
# +logger+ - Pass your logger, default is Logger.new($stdout)
|
|
37
42
|
#
|
|
38
43
|
attr_reader(*OPTIONS)
|
|
@@ -51,6 +56,10 @@ module Flagsmith
|
|
|
51
56
|
@enable_analytics
|
|
52
57
|
end
|
|
53
58
|
|
|
59
|
+
def offline_mode?
|
|
60
|
+
@offline_mode
|
|
61
|
+
end
|
|
62
|
+
|
|
54
63
|
def environment_flags_url
|
|
55
64
|
'flags/'
|
|
56
65
|
end
|
|
@@ -78,6 +87,8 @@ module Flagsmith
|
|
|
78
87
|
@environment_refresh_interval_seconds = opts.fetch(:environment_refresh_interval_seconds, 60)
|
|
79
88
|
@enable_analytics = opts.fetch(:enable_analytics, false)
|
|
80
89
|
@default_flag_handler = opts[:default_flag_handler]
|
|
90
|
+
@offline_mode = opts.fetch(:offline_mode, false)
|
|
91
|
+
@offline_handler = opts[:offline_handler]
|
|
81
92
|
@logger = options.fetch(:logger, Logger.new($stdout).tap { |l| l.level = :debug })
|
|
82
93
|
end
|
|
83
94
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
@@ -84,12 +84,13 @@ module Flagsmith
|
|
|
84
84
|
class Collection
|
|
85
85
|
include Enumerable
|
|
86
86
|
|
|
87
|
-
attr_reader :flags, :default_flag_handler, :analytics_processor
|
|
87
|
+
attr_reader :flags, :default_flag_handler, :analytics_processor, :offline_handler
|
|
88
88
|
|
|
89
|
-
def initialize(flags = {}, analytics_processor: nil, default_flag_handler: nil)
|
|
89
|
+
def initialize(flags = {}, analytics_processor: nil, default_flag_handler: nil, offline_handler: nil)
|
|
90
90
|
@flags = flags
|
|
91
91
|
@default_flag_handler = default_flag_handler
|
|
92
92
|
@analytics_processor = analytics_processor
|
|
93
|
+
@offline_handler = offline_handler
|
|
93
94
|
end
|
|
94
95
|
|
|
95
96
|
def each(&block)
|
|
@@ -119,16 +120,27 @@ module Flagsmith
|
|
|
119
120
|
end
|
|
120
121
|
alias get_feature_value feature_value
|
|
121
122
|
|
|
123
|
+
def get_flag_from_offline_handler(key)
|
|
124
|
+
@offline_handler.environment.feature_states.each do |feature_state|
|
|
125
|
+
return Flag.from_feature_state_model(feature_state, nil) if key == Flagsmith::Flags::Collection.normalize_key(feature_state.feature.name)
|
|
126
|
+
end
|
|
127
|
+
raise Flagsmith::Flags::NotFound,
|
|
128
|
+
"Feature does not exist: #{key}, offline_handler did not find a flag in this case."
|
|
129
|
+
end
|
|
130
|
+
|
|
122
131
|
# Get a specific flag given the feature name.
|
|
123
132
|
# :param feature_name: the name of the feature to retrieve the flag for.
|
|
124
133
|
# :return: BaseFlag object.
|
|
125
134
|
# :raises FlagsmithClientError: if feature doesn't exist
|
|
126
135
|
def get_flag(feature_name)
|
|
127
136
|
key = Flagsmith::Flags::Collection.normalize_key(feature_name)
|
|
137
|
+
|
|
128
138
|
flag = flags.fetch(key)
|
|
129
139
|
@analytics_processor.track_feature(flag.feature_name) if @analytics_processor && flag.feature_id
|
|
130
140
|
flag
|
|
131
141
|
rescue KeyError
|
|
142
|
+
return get_flag_from_offline_handler(key) if @offline_handler
|
|
143
|
+
|
|
132
144
|
return @default_flag_handler.call(feature_name) if @default_flag_handler
|
|
133
145
|
|
|
134
146
|
raise Flagsmith::Flags::NotFound,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Flagsmith
|
|
4
|
+
module OfflineHandlers
|
|
5
|
+
# Provides the offline_handler to the Flagsmith::Client.
|
|
6
|
+
class LocalFileHandler
|
|
7
|
+
attr_reader :environment
|
|
8
|
+
|
|
9
|
+
def initialize(environment_document_path)
|
|
10
|
+
environment_file = File.open(environment_document_path)
|
|
11
|
+
|
|
12
|
+
data = JSON.parse(environment_file.read, symbolize_names: true)
|
|
13
|
+
@environment = Flagsmith::Engine::Environment.build(data)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/flagsmith/version.rb
CHANGED
data/lib/flagsmith.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'pry'
|
|
4
|
+
require 'pry-byebug'
|
|
5
|
+
|
|
3
6
|
require 'faraday'
|
|
4
7
|
require 'faraday/retry'
|
|
5
|
-
require 'faraday_middleware'
|
|
6
8
|
|
|
7
9
|
# Hash#slice was added in ruby version 2.5
|
|
8
10
|
# This is the patch to use slice in earler versions
|
|
@@ -16,6 +18,7 @@ require 'flagsmith/sdk/intervals'
|
|
|
16
18
|
require 'flagsmith/sdk/pooling_manager'
|
|
17
19
|
require 'flagsmith/sdk/models/flags'
|
|
18
20
|
require 'flagsmith/sdk/models/segments'
|
|
21
|
+
require 'flagsmith/sdk/offline_handlers'
|
|
19
22
|
|
|
20
23
|
require 'flagsmith/engine/core'
|
|
21
24
|
|
|
@@ -44,7 +47,9 @@ module Flagsmith
|
|
|
44
47
|
# Available Configs.
|
|
45
48
|
#
|
|
46
49
|
# :environment_key, :api_url, :custom_headers, :request_timeout_seconds, :enable_local_evaluation,
|
|
47
|
-
# :environment_refresh_interval_seconds, :retries, :enable_analytics, :default_flag_handler
|
|
50
|
+
# :environment_refresh_interval_seconds, :retries, :enable_analytics, :default_flag_handler,
|
|
51
|
+
# :offline_mode, :offline_handler
|
|
52
|
+
#
|
|
48
53
|
# You can see full description in the Flagsmith::Config
|
|
49
54
|
|
|
50
55
|
attr_reader :config, :environment
|
|
@@ -55,10 +60,24 @@ module Flagsmith
|
|
|
55
60
|
@_mutex = Mutex.new
|
|
56
61
|
@config = Flagsmith::Config.new(config)
|
|
57
62
|
|
|
63
|
+
validate_offline_mode!
|
|
64
|
+
|
|
58
65
|
api_client
|
|
59
66
|
analytics_processor
|
|
60
67
|
environment_data_polling_manager
|
|
61
68
|
engine
|
|
69
|
+
load_offline_handler
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def validate_offline_mode!
|
|
73
|
+
if @config.offline_mode? && !@config.offline_handler
|
|
74
|
+
raise Flagsmith::ClientError,
|
|
75
|
+
'The offline_mode config param requires a matching offline_handler.'
|
|
76
|
+
end
|
|
77
|
+
return unless @config.offline_handler && @config.default_flag_handler
|
|
78
|
+
|
|
79
|
+
raise Flagsmith::ClientError,
|
|
80
|
+
'Cannot use offline_handler and default_flag_handler at the same time.'
|
|
62
81
|
end
|
|
63
82
|
|
|
64
83
|
def api_client
|
|
@@ -79,6 +98,10 @@ module Flagsmith
|
|
|
79
98
|
)
|
|
80
99
|
end
|
|
81
100
|
|
|
101
|
+
def load_offline_handler
|
|
102
|
+
@environment = offline_handler.environment if offline_handler
|
|
103
|
+
end
|
|
104
|
+
|
|
82
105
|
def environment_data_polling_manager
|
|
83
106
|
return nil unless @config.local_evaluation?
|
|
84
107
|
|
|
@@ -103,7 +126,7 @@ module Flagsmith
|
|
|
103
126
|
# Get all the default for flags for the current environment.
|
|
104
127
|
# @returns Flags object holding all the flags for the current environment.
|
|
105
128
|
def get_environment_flags # rubocop:disable Naming/AccessorMethodName
|
|
106
|
-
return environment_flags_from_document if @config.local_evaluation?
|
|
129
|
+
return environment_flags_from_document if @config.local_evaluation? || @config.offline_mode
|
|
107
130
|
|
|
108
131
|
environment_flags_from_api
|
|
109
132
|
end
|
|
@@ -154,7 +177,7 @@ module Flagsmith
|
|
|
154
177
|
def get_identity_segments(identifier, traits = {})
|
|
155
178
|
unless environment
|
|
156
179
|
raise Flagsmith::ClientError,
|
|
157
|
-
'Local evaluation required to obtain identity segments.'
|
|
180
|
+
'Local evaluation or offline handler is required to obtain identity segments.'
|
|
158
181
|
end
|
|
159
182
|
|
|
160
183
|
identity_model = build_identity_model(identifier, traits)
|
|
@@ -168,7 +191,8 @@ module Flagsmith
|
|
|
168
191
|
Flagsmith::Flags::Collection.from_feature_state_models(
|
|
169
192
|
engine.get_environment_feature_states(environment),
|
|
170
193
|
analytics_processor: analytics_processor,
|
|
171
|
-
default_flag_handler: default_flag_handler
|
|
194
|
+
default_flag_handler: default_flag_handler,
|
|
195
|
+
offline_handler: offline_handler
|
|
172
196
|
)
|
|
173
197
|
end
|
|
174
198
|
|
|
@@ -178,45 +202,80 @@ module Flagsmith
|
|
|
178
202
|
Flagsmith::Flags::Collection.from_feature_state_models(
|
|
179
203
|
engine.get_identity_feature_states(environment, identity_model),
|
|
180
204
|
analytics_processor: analytics_processor,
|
|
181
|
-
default_flag_handler: default_flag_handler
|
|
205
|
+
default_flag_handler: default_flag_handler,
|
|
206
|
+
offline_handler: offline_handler
|
|
182
207
|
)
|
|
183
208
|
end
|
|
184
209
|
|
|
210
|
+
# rubocop:disable Metrics/MethodLength
|
|
185
211
|
def environment_flags_from_api
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
212
|
+
if offline_handler
|
|
213
|
+
begin
|
|
214
|
+
process_environment_flags_from_api
|
|
215
|
+
rescue StandardError
|
|
216
|
+
environment_flags_from_document
|
|
217
|
+
end
|
|
218
|
+
else
|
|
219
|
+
begin
|
|
220
|
+
process_environment_flags_from_api
|
|
221
|
+
rescue StandardError
|
|
222
|
+
if default_flag_handler
|
|
223
|
+
return Flagsmith::Flags::Collection.new(
|
|
224
|
+
{},
|
|
225
|
+
default_flag_handler: default_flag_handler
|
|
226
|
+
)
|
|
227
|
+
end
|
|
228
|
+
raise
|
|
229
|
+
end
|
|
194
230
|
end
|
|
195
231
|
end
|
|
232
|
+
# rubocop:enable Metrics/MethodLength
|
|
196
233
|
|
|
234
|
+
def process_environment_flags_from_api
|
|
235
|
+
api_flags = api_client.get(@config.environment_flags_url).body
|
|
236
|
+
api_flags = api_flags.select { |flag| flag[:feature_segment].nil? }
|
|
237
|
+
Flagsmith::Flags::Collection.from_api(
|
|
238
|
+
api_flags,
|
|
239
|
+
analytics_processor: analytics_processor,
|
|
240
|
+
default_flag_handler: default_flag_handler,
|
|
241
|
+
offline_handler: offline_handler
|
|
242
|
+
)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# rubocop:disable Metrics/MethodLength
|
|
197
246
|
def get_identity_flags_from_api(identifier, traits = {})
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
247
|
+
if offline_handler
|
|
248
|
+
begin
|
|
249
|
+
process_identity_flags_from_api(identifier, traits)
|
|
250
|
+
rescue StandardError
|
|
251
|
+
get_identity_flags_from_document(identifier, traits)
|
|
252
|
+
end
|
|
253
|
+
else
|
|
254
|
+
begin
|
|
255
|
+
process_identity_flags_from_api(identifier, traits)
|
|
256
|
+
rescue StandardError
|
|
257
|
+
if default_flag_handler
|
|
258
|
+
return Flagsmith::Flags::Collection.new(
|
|
259
|
+
{},
|
|
260
|
+
default_flag_handler: default_flag_handler
|
|
261
|
+
)
|
|
262
|
+
end
|
|
263
|
+
raise
|
|
264
|
+
end
|
|
207
265
|
end
|
|
208
266
|
end
|
|
267
|
+
# rubocop:enable Metrics/MethodLength
|
|
209
268
|
|
|
210
|
-
def
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
269
|
+
def process_identity_flags_from_api(identifier, traits = {})
|
|
270
|
+
data = generate_identities_data(identifier, traits)
|
|
271
|
+
json_response = api_client.post(@config.identities_url, data.to_json).body
|
|
272
|
+
|
|
273
|
+
Flagsmith::Flags::Collection.from_api(
|
|
274
|
+
json_response[:flags],
|
|
275
|
+
analytics_processor: analytics_processor,
|
|
276
|
+
default_flag_handler: default_flag_handler,
|
|
277
|
+
offline_handler: offline_handler
|
|
278
|
+
)
|
|
220
279
|
end
|
|
221
280
|
|
|
222
281
|
def build_identity_model(identifier, traits = {})
|
metadata
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flagsmith
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom Stuart
|
|
8
8
|
- Brian Moelk
|
|
9
|
+
- Zach Aysan
|
|
9
10
|
autorequire:
|
|
10
11
|
bindir: exe
|
|
11
12
|
cert_chain: []
|
|
12
|
-
date:
|
|
13
|
+
date: 2024-01-30 00:00:00.000000000 Z
|
|
13
14
|
dependencies:
|
|
14
15
|
- !ruby/object:Gem::Dependency
|
|
15
16
|
name: bundler
|
|
@@ -54,7 +55,7 @@ dependencies:
|
|
|
54
55
|
- !ruby/object:Gem::Version
|
|
55
56
|
version: '0'
|
|
56
57
|
- !ruby/object:Gem::Dependency
|
|
57
|
-
name:
|
|
58
|
+
name: pry-byebug
|
|
58
59
|
requirement: !ruby/object:Gem::Requirement
|
|
59
60
|
requirements:
|
|
60
61
|
- - ">="
|
|
@@ -68,7 +69,7 @@ dependencies:
|
|
|
68
69
|
- !ruby/object:Gem::Version
|
|
69
70
|
version: '0'
|
|
70
71
|
- !ruby/object:Gem::Dependency
|
|
71
|
-
name:
|
|
72
|
+
name: rake
|
|
72
73
|
requirement: !ruby/object:Gem::Requirement
|
|
73
74
|
requirements:
|
|
74
75
|
- - ">="
|
|
@@ -82,7 +83,7 @@ dependencies:
|
|
|
82
83
|
- !ruby/object:Gem::Version
|
|
83
84
|
version: '0'
|
|
84
85
|
- !ruby/object:Gem::Dependency
|
|
85
|
-
name:
|
|
86
|
+
name: rspec
|
|
86
87
|
requirement: !ruby/object:Gem::Requirement
|
|
87
88
|
requirements:
|
|
88
89
|
- - ">="
|
|
@@ -96,13 +97,13 @@ dependencies:
|
|
|
96
97
|
- !ruby/object:Gem::Version
|
|
97
98
|
version: '0'
|
|
98
99
|
- !ruby/object:Gem::Dependency
|
|
99
|
-
name:
|
|
100
|
+
name: rubocop
|
|
100
101
|
requirement: !ruby/object:Gem::Requirement
|
|
101
102
|
requirements:
|
|
102
103
|
- - ">="
|
|
103
104
|
- !ruby/object:Gem::Version
|
|
104
105
|
version: '0'
|
|
105
|
-
type: :
|
|
106
|
+
type: :development
|
|
106
107
|
prerelease: false
|
|
107
108
|
version_requirements: !ruby/object:Gem::Requirement
|
|
108
109
|
requirements:
|
|
@@ -110,19 +111,19 @@ dependencies:
|
|
|
110
111
|
- !ruby/object:Gem::Version
|
|
111
112
|
version: '0'
|
|
112
113
|
- !ruby/object:Gem::Dependency
|
|
113
|
-
name:
|
|
114
|
+
name: faraday
|
|
114
115
|
requirement: !ruby/object:Gem::Requirement
|
|
115
116
|
requirements:
|
|
116
117
|
- - ">="
|
|
117
118
|
- !ruby/object:Gem::Version
|
|
118
|
-
version:
|
|
119
|
+
version: 2.0.1
|
|
119
120
|
type: :runtime
|
|
120
121
|
prerelease: false
|
|
121
122
|
version_requirements: !ruby/object:Gem::Requirement
|
|
122
123
|
requirements:
|
|
123
124
|
- - ">="
|
|
124
125
|
- !ruby/object:Gem::Version
|
|
125
|
-
version:
|
|
126
|
+
version: 2.0.1
|
|
126
127
|
- !ruby/object:Gem::Dependency
|
|
127
128
|
name: faraday-retry
|
|
128
129
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -156,6 +157,7 @@ description: Ruby Client for Flagsmith. Ship features with confidence using feat
|
|
|
156
157
|
email:
|
|
157
158
|
- tom@solidstategroup.com
|
|
158
159
|
- bmoelk@gmail.com
|
|
160
|
+
- zachaysan@gmail.com
|
|
159
161
|
executables: []
|
|
160
162
|
extensions: []
|
|
161
163
|
extra_rdoc_files: []
|
|
@@ -224,6 +226,7 @@ files:
|
|
|
224
226
|
- lib/flagsmith/sdk/intervals.rb
|
|
225
227
|
- lib/flagsmith/sdk/models/flags.rb
|
|
226
228
|
- lib/flagsmith/sdk/models/segments.rb
|
|
229
|
+
- lib/flagsmith/sdk/offline_handlers.rb
|
|
227
230
|
- lib/flagsmith/sdk/pooling_manager.rb
|
|
228
231
|
- lib/flagsmith/version.rb
|
|
229
232
|
homepage: https://flagsmith.com
|
|
@@ -238,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
238
241
|
requirements:
|
|
239
242
|
- - ">="
|
|
240
243
|
- !ruby/object:Gem::Version
|
|
241
|
-
version:
|
|
244
|
+
version: 3.0.0
|
|
242
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
246
|
requirements:
|
|
244
247
|
- - ">="
|