flagsmith 3.2.0 → 4.0.1
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 +89 -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: bf49e28a71c8b23ec9ec005b827dd4354cef0471504ca65e40808d4c206f65ad
|
|
4
|
+
data.tar.gz: de53c7c6d6d17918b5a8ffdf0bdc505a641a63cb637d3dd74ac26c7da5442a99
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff47303eae7c600cf32807a4b3aad303fa8fbac31678570d9262366e152e96342083ed31f9f8be91614ebfee10c525707ae66ec418a193dc32c35513686816bd
|
|
7
|
+
data.tar.gz: 0d2cc7b84114d1595c93c8e6adea2aa4de9e8f3576bd3bd2cab0fcaac54131ec25ba5cbdd7f74cf795b8846f74aeeeabf9fd0bccadf99e98c104030a134fa4f3
|
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.1)
|
|
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
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require 'faraday'
|
|
4
4
|
require 'faraday/retry'
|
|
5
|
-
require 'faraday_middleware'
|
|
6
5
|
|
|
7
6
|
# Hash#slice was added in ruby version 2.5
|
|
8
7
|
# This is the patch to use slice in earler versions
|
|
@@ -16,6 +15,7 @@ require 'flagsmith/sdk/intervals'
|
|
|
16
15
|
require 'flagsmith/sdk/pooling_manager'
|
|
17
16
|
require 'flagsmith/sdk/models/flags'
|
|
18
17
|
require 'flagsmith/sdk/models/segments'
|
|
18
|
+
require 'flagsmith/sdk/offline_handlers'
|
|
19
19
|
|
|
20
20
|
require 'flagsmith/engine/core'
|
|
21
21
|
|
|
@@ -44,7 +44,9 @@ module Flagsmith
|
|
|
44
44
|
# Available Configs.
|
|
45
45
|
#
|
|
46
46
|
# :environment_key, :api_url, :custom_headers, :request_timeout_seconds, :enable_local_evaluation,
|
|
47
|
-
# :environment_refresh_interval_seconds, :retries, :enable_analytics, :default_flag_handler
|
|
47
|
+
# :environment_refresh_interval_seconds, :retries, :enable_analytics, :default_flag_handler,
|
|
48
|
+
# :offline_mode, :offline_handler
|
|
49
|
+
#
|
|
48
50
|
# You can see full description in the Flagsmith::Config
|
|
49
51
|
|
|
50
52
|
attr_reader :config, :environment
|
|
@@ -55,10 +57,24 @@ module Flagsmith
|
|
|
55
57
|
@_mutex = Mutex.new
|
|
56
58
|
@config = Flagsmith::Config.new(config)
|
|
57
59
|
|
|
60
|
+
validate_offline_mode!
|
|
61
|
+
|
|
58
62
|
api_client
|
|
59
63
|
analytics_processor
|
|
60
64
|
environment_data_polling_manager
|
|
61
65
|
engine
|
|
66
|
+
load_offline_handler
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def validate_offline_mode!
|
|
70
|
+
if @config.offline_mode? && !@config.offline_handler
|
|
71
|
+
raise Flagsmith::ClientError,
|
|
72
|
+
'The offline_mode config param requires a matching offline_handler.'
|
|
73
|
+
end
|
|
74
|
+
return unless @config.offline_handler && @config.default_flag_handler
|
|
75
|
+
|
|
76
|
+
raise Flagsmith::ClientError,
|
|
77
|
+
'Cannot use offline_handler and default_flag_handler at the same time.'
|
|
62
78
|
end
|
|
63
79
|
|
|
64
80
|
def api_client
|
|
@@ -79,6 +95,10 @@ module Flagsmith
|
|
|
79
95
|
)
|
|
80
96
|
end
|
|
81
97
|
|
|
98
|
+
def load_offline_handler
|
|
99
|
+
@environment = offline_handler.environment if offline_handler
|
|
100
|
+
end
|
|
101
|
+
|
|
82
102
|
def environment_data_polling_manager
|
|
83
103
|
return nil unless @config.local_evaluation?
|
|
84
104
|
|
|
@@ -103,7 +123,7 @@ module Flagsmith
|
|
|
103
123
|
# Get all the default for flags for the current environment.
|
|
104
124
|
# @returns Flags object holding all the flags for the current environment.
|
|
105
125
|
def get_environment_flags # rubocop:disable Naming/AccessorMethodName
|
|
106
|
-
return environment_flags_from_document if @config.local_evaluation?
|
|
126
|
+
return environment_flags_from_document if @config.local_evaluation? || @config.offline_mode
|
|
107
127
|
|
|
108
128
|
environment_flags_from_api
|
|
109
129
|
end
|
|
@@ -154,7 +174,7 @@ module Flagsmith
|
|
|
154
174
|
def get_identity_segments(identifier, traits = {})
|
|
155
175
|
unless environment
|
|
156
176
|
raise Flagsmith::ClientError,
|
|
157
|
-
'Local evaluation required to obtain identity segments.'
|
|
177
|
+
'Local evaluation or offline handler is required to obtain identity segments.'
|
|
158
178
|
end
|
|
159
179
|
|
|
160
180
|
identity_model = build_identity_model(identifier, traits)
|
|
@@ -168,7 +188,8 @@ module Flagsmith
|
|
|
168
188
|
Flagsmith::Flags::Collection.from_feature_state_models(
|
|
169
189
|
engine.get_environment_feature_states(environment),
|
|
170
190
|
analytics_processor: analytics_processor,
|
|
171
|
-
default_flag_handler: default_flag_handler
|
|
191
|
+
default_flag_handler: default_flag_handler,
|
|
192
|
+
offline_handler: offline_handler
|
|
172
193
|
)
|
|
173
194
|
end
|
|
174
195
|
|
|
@@ -178,45 +199,80 @@ module Flagsmith
|
|
|
178
199
|
Flagsmith::Flags::Collection.from_feature_state_models(
|
|
179
200
|
engine.get_identity_feature_states(environment, identity_model),
|
|
180
201
|
analytics_processor: analytics_processor,
|
|
181
|
-
default_flag_handler: default_flag_handler
|
|
202
|
+
default_flag_handler: default_flag_handler,
|
|
203
|
+
offline_handler: offline_handler
|
|
182
204
|
)
|
|
183
205
|
end
|
|
184
206
|
|
|
207
|
+
# rubocop:disable Metrics/MethodLength
|
|
185
208
|
def environment_flags_from_api
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
209
|
+
if offline_handler
|
|
210
|
+
begin
|
|
211
|
+
process_environment_flags_from_api
|
|
212
|
+
rescue StandardError
|
|
213
|
+
environment_flags_from_document
|
|
214
|
+
end
|
|
215
|
+
else
|
|
216
|
+
begin
|
|
217
|
+
process_environment_flags_from_api
|
|
218
|
+
rescue StandardError
|
|
219
|
+
if default_flag_handler
|
|
220
|
+
return Flagsmith::Flags::Collection.new(
|
|
221
|
+
{},
|
|
222
|
+
default_flag_handler: default_flag_handler
|
|
223
|
+
)
|
|
224
|
+
end
|
|
225
|
+
raise
|
|
226
|
+
end
|
|
194
227
|
end
|
|
195
228
|
end
|
|
229
|
+
# rubocop:enable Metrics/MethodLength
|
|
196
230
|
|
|
231
|
+
def process_environment_flags_from_api
|
|
232
|
+
api_flags = api_client.get(@config.environment_flags_url).body
|
|
233
|
+
api_flags = api_flags.select { |flag| flag[:feature_segment].nil? }
|
|
234
|
+
Flagsmith::Flags::Collection.from_api(
|
|
235
|
+
api_flags,
|
|
236
|
+
analytics_processor: analytics_processor,
|
|
237
|
+
default_flag_handler: default_flag_handler,
|
|
238
|
+
offline_handler: offline_handler
|
|
239
|
+
)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# rubocop:disable Metrics/MethodLength
|
|
197
243
|
def get_identity_flags_from_api(identifier, traits = {})
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
244
|
+
if offline_handler
|
|
245
|
+
begin
|
|
246
|
+
process_identity_flags_from_api(identifier, traits)
|
|
247
|
+
rescue StandardError
|
|
248
|
+
get_identity_flags_from_document(identifier, traits)
|
|
249
|
+
end
|
|
250
|
+
else
|
|
251
|
+
begin
|
|
252
|
+
process_identity_flags_from_api(identifier, traits)
|
|
253
|
+
rescue StandardError
|
|
254
|
+
if default_flag_handler
|
|
255
|
+
return Flagsmith::Flags::Collection.new(
|
|
256
|
+
{},
|
|
257
|
+
default_flag_handler: default_flag_handler
|
|
258
|
+
)
|
|
259
|
+
end
|
|
260
|
+
raise
|
|
261
|
+
end
|
|
207
262
|
end
|
|
208
263
|
end
|
|
264
|
+
# rubocop:enable Metrics/MethodLength
|
|
209
265
|
|
|
210
|
-
def
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
266
|
+
def process_identity_flags_from_api(identifier, traits = {})
|
|
267
|
+
data = generate_identities_data(identifier, traits)
|
|
268
|
+
json_response = api_client.post(@config.identities_url, data.to_json).body
|
|
269
|
+
|
|
270
|
+
Flagsmith::Flags::Collection.from_api(
|
|
271
|
+
json_response[:flags],
|
|
272
|
+
analytics_processor: analytics_processor,
|
|
273
|
+
default_flag_handler: default_flag_handler,
|
|
274
|
+
offline_handler: offline_handler
|
|
275
|
+
)
|
|
220
276
|
end
|
|
221
277
|
|
|
222
278
|
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.1
|
|
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-02-06 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
|
- - ">="
|