Class: Flipper::Adapters::FirebaseRemoteConfig
- Inherits:
-
Object
- Object
- Flipper::Adapters::FirebaseRemoteConfig
show all
- Defined in:
- lib/flipper/adapters/firebase_remote_config.rb,
lib/flipper/adapters/firebase_remote_config/client.rb,
lib/flipper/adapters/firebase_remote_config/version.rb
Overview
Flipper adapter that stores feature state as Firebase Remote Config parameters. One parameter per feature; an index parameter tracks the known feature keys so listing doesn’t have to scan the whole template.
The in-memory representation of a template is the raw API JSON shape:
{
"parameters" => {
"flipper__search" => {
"valueType" => "JSON",
"defaultValue" => { "value" => "{\"boolean\":\"true\",...}" }
},
"flipper____index__" => { ... JSON array of feature keys ... }
},
"conditions" => [...],
...
}
See README.md for the rationale and for caveats (eventual consistency, write quotas, no support for Remote Config conditions in v0.1).
Defined Under Namespace
Classes: Client, ETagMismatch, Error
Constant Summary
collapse
- DEFAULT_PREFIX =
'flipper__'.freeze
- INDEX_SUFFIX =
'__index__'.freeze
- DEFAULT_CACHE_TTL =
30
- SCOPE =
'https://www.googleapis.com/auth/firebase.remoteconfig'.freeze
- API_HOST =
'firebaseremoteconfig.googleapis.com'.freeze
- OPEN_TIMEOUT =
5
- READ_TIMEOUT =
15
- VERSION =
'0.0.1'.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(project_id: nil, credentials: nil, client: nil, prefix: DEFAULT_PREFIX, cache_ttl: DEFAULT_CACHE_TTL) ⇒ FirebaseRemoteConfig
Returns a new instance of FirebaseRemoteConfig.
36
37
38
39
40
41
42
43
44
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 36
def initialize(project_id: nil, credentials: nil, client: nil,
prefix: DEFAULT_PREFIX, cache_ttl: DEFAULT_CACHE_TTL)
@name = :firebase_remote_config
@prefix = prefix
@cache_ttl = cache_ttl
@client = client || Client.new(project_id: project_id, credentials: credentials)
@cache = nil
@cached_at = nil
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
34
35
36
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 34
def name
@name
end
|
Instance Method Details
#add(feature) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 50
def add(feature)
with_template do |template|
ensure_parameter(template, feature.key)
add_to_index(template, feature.key)
end
true
end
|
#clear(feature) ⇒ Object
66
67
68
69
70
71
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 66
def clear(feature)
with_template do |template|
write_gates(template, feature.key, default_config)
end
true
end
|
#disable(feature, gate, thing) ⇒ Object
96
97
98
99
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 96
def disable(feature, gate, thing)
mutate_gates(feature) { |gates| apply_disable_gate(gates, gate, thing) }
true
end
|
#enable(feature, gate, thing) ⇒ Object
91
92
93
94
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 91
def enable(feature, gate, thing)
mutate_gates(feature) { |gates| apply_enable_gate(gates, gate, thing) }
true
end
|
#features ⇒ Object
46
47
48
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 46
def features
Set.new(index_from(load_template))
end
|
#get(feature) ⇒ Object
73
74
75
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 73
def get(feature)
read_gates(load_template, feature.key)
end
|
#get_all ⇒ Object
84
85
86
87
88
89
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 84
def get_all
template = load_template
index_from(template).to_h do |feature_key|
[feature_key, read_gates(template, feature_key)]
end
end
|
#get_multi(features) ⇒ Object
77
78
79
80
81
82
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 77
def get_multi(features)
template = load_template
features.to_h do |feature|
[feature.key, read_gates(template, feature.key)]
end
end
|
#reload! ⇒ Object
Drop the in-process cache. Call this when you know the template has drifted (e.g. another process published a new version).
103
104
105
106
107
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 103
def reload!
@cache = nil
@cached_at = nil
self
end
|
#remove(feature) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/flipper/adapters/firebase_remote_config.rb', line 58
def remove(feature)
with_template do |template|
template['parameters']&.delete(parameter_name(feature.key))
remove_from_index(template, feature.key)
end
true
end
|