Class: Flipper::Adapters::ActorLimit

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

Constant Summary collapse

LimitExceeded =
Class.new(Flipper::Error)

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, #get_multi, #import, included, #name, #read_only?

Constructor Details

#initialize(adapter, limit = 100) ⇒ ActorLimit



34
35
36
37
# File 'lib/flipper/adapters/actor_limit.rb', line 34

def initialize(adapter, limit = 100)
  super(adapter)
  @limit = limit
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



8
9
10
# File 'lib/flipper/adapters/actor_limit.rb', line 8

def limit
  @limit
end

Class Method Details

.sync_modeObject

Returns whether sync mode is enabled for the current thread. When sync mode is enabled, actor limits are not enforced, allowing sync operations to bring local state in line with remote state regardless of limits.



15
16
17
# File 'lib/flipper/adapters/actor_limit.rb', line 15

def sync_mode
  Thread.current[:flipper_actor_limit_sync_mode]
end

.sync_mode=(value) ⇒ Object



19
20
21
# File 'lib/flipper/adapters/actor_limit.rb', line 19

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

.with_sync_modeObject

Executes a block with sync mode enabled. Actor limits will not be enforced within the block.



25
26
27
28
29
30
31
# File 'lib/flipper/adapters/actor_limit.rb', line 25

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

Instance Method Details

#enable(feature, gate, resource) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/flipper/adapters/actor_limit.rb', line 39

def enable(feature, gate, resource)
  if gate.is_a?(Flipper::Gates::Actor) && !self.class.sync_mode && over_limit?(feature)
    raise LimitExceeded, "Actor limit of #{@limit} exceeded for feature #{feature.key}. See https://www.flippercloud.io/docs/features/actors#limitations"
  else
    super
  end
end