Class: Flipper::Adapters::Strict

Inherits:
Wrapper
  • Object
show all
Defined in:
lib/flipper/adapters/strict.rb

Overview

An adapter that ensures a feature exists before checking it.

Defined Under Namespace

Classes: NotFound

Constant Summary

Constants inherited from Wrapper

Wrapper::METHODS

Instance Attribute Summary collapse

Attributes inherited from Wrapper

#adapter

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Wrapper

#wrap

Methods included from Flipper::Adapter

#adapter_stack, #default_config, #export, #get_all, #import, included, #name, #read_only?

Constructor Details

#initialize(adapter, handler = nil, &block) ⇒ Strict

Returns a new instance of Strict.



37
38
39
40
# File 'lib/flipper/adapters/strict.rb', line 37

def initialize(adapter, handler = nil, &block)
  super(adapter)
  @handler = block || handler
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



5
6
7
# File 'lib/flipper/adapters/strict.rb', line 5

def handler
  @handler
end

Class Method Details

.sync_modeObject

Returns whether sync mode is enabled for the current thread. When sync mode is enabled, strict checks are not enforced, allowing sync operations to add features and bring local state in line with remote state.



18
19
20
# File 'lib/flipper/adapters/strict.rb', line 18

def sync_mode
  Thread.current[:flipper_strict_sync_mode]
end

.sync_mode=(value) ⇒ Object



22
23
24
# File 'lib/flipper/adapters/strict.rb', line 22

def sync_mode=(value)
  Thread.current[:flipper_strict_sync_mode] = value
end

.with_sync_modeObject

Executes a block with sync mode enabled. Strict checks will not be enforced within the block.



28
29
30
31
32
33
34
# File 'lib/flipper/adapters/strict.rb', line 28

def with_sync_mode
  old_value = sync_mode
  self.sync_mode = true
  yield
ensure
  self.sync_mode = old_value
end

Instance Method Details

#add(feature) ⇒ Object



42
43
44
45
# File 'lib/flipper/adapters/strict.rb', line 42

def add(feature)
  assert_feature_exists(feature) unless self.class.sync_mode
  super
end

#get(feature) ⇒ Object



47
48
49
50
# File 'lib/flipper/adapters/strict.rb', line 47

def get(feature)
  assert_feature_exists(feature)
  super
end

#get_multi(features) ⇒ Object



52
53
54
55
# File 'lib/flipper/adapters/strict.rb', line 52

def get_multi(features)
  features.each { |feature| assert_feature_exists(feature) }
  super
end