File: memoizing.rb

package info (click to toggle)
ruby-flipper 0.26.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,296 kB
  • sloc: ruby: 16,377; sh: 61; javascript: 24; makefile: 14
file content (35 lines) | stat: -rw-r--r-- 966 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'bundler/setup'
require 'flipper'
require 'flipper/adapters/operation_logger'
require 'flipper/instrumentation/log_subscriber'

Flipper.configure do |config|
  config.adapter do
    # pick an adapter, this uses memory, any will do
    Flipper::Adapters::OperationLogger.new(Flipper::Adapters::Memory.new)
  end
end

Flipper.enable(:foo)
Flipper.enable(:bar)
Flipper.disable(:baz)
Flipper.disable(:wick)
# reset the operation logging adapter to empty for clarity
Flipper.adapter.reset

# Turn on memoization (the memoizing middleware does this per request).
Flipper.memoize = true

# Preload all the features.
Flipper.preload_all

# Do as many feature checks as your heart desires.
%w[foo bar baz wick].each do |name|
  Flipper.enabled?(name)
end

# See that only one operation exists, a get_all (which is the preload_all).
pp Flipper.adapter.operations
# [#<Flipper::Adapters::OperationLogger::Operation:0x00007fdcfe1100e8
#   @args=[],
#   @type=:get_all>]