Class: Flipper::Adapters::Strict

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Flipper::Adapter
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 collapse

HANDLERS =
{
  raise: ->(feature) { raise NotFound.new(feature.key) },
  warn: ->(feature) { warn NotFound.new(feature.key).message },
  noop: ->(_) { },
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Flipper::Adapter

#default_config, #export, #get_all, #import, included

Constructor Details

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

Returns a new instance of Strict.



23
24
25
26
27
# File 'lib/flipper/adapters/strict.rb', line 23

def initialize(adapter, handler = nil, &block)
  @name = :strict
  @adapter = adapter
  @handler = block || HANDLERS.fetch(handler)
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



7
8
9
# File 'lib/flipper/adapters/strict.rb', line 7

def adapter
  @adapter
end

#handlerObject (readonly)

Returns the value of attribute handler.



7
8
9
# File 'lib/flipper/adapters/strict.rb', line 7

def handler
  @handler
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/flipper/adapters/strict.rb', line 7

def name
  @name
end

Instance Method Details

#get(feature) ⇒ Object



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

def get(feature)
  assert_feature_exists(feature)
  @adapter.get(feature)
end

#get_multi(features) ⇒ Object



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

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