SandboxCase.Sandbox.FwfAdapter (sandbox_case v0.4.0)

Copy Markdown View Source

A sandbox-aware FunWithFlags.Store.Persistent adapter.

This is the no-bytecode-patching replacement for FwfPatcher. It is a normal FunWithFlags persistence adapter (a documented extension point): on every flag operation it checks the process dictionary (and $callers) for a :fwf_sandbox ETS table. When one is present — i.e. inside a sandboxed test — reads and writes route to that isolated table (via FwfStore). When absent, it delegates to the project's real persistence adapter, so production/non-sandboxed code paths are unchanged.

Configuration

config :fun_with_flags, :persistence,
  adapter: SandboxCase.Sandbox.FwfAdapter,
  sandbox_real_adapter: FunWithFlags.Store.Persistent.Ecto,
  repo: MyApp.Repo            # opts for the real adapter, passed through

# The FunWithFlags cache must be off so every lookup reaches the
# (sandbox-aware) store rather than a shared global ETS cache:
config :fun_with_flags, :cache, enabled: false

:sandbox_real_adapter is the adapter to use when NOT sandboxed; it must be a different module than this one (otherwise lookups would recurse). All other keys under :persistence are read by the real adapter as usual.

Summary

Functions

all_flag_names()

all_flags()

delete(flag_name)

delete(flag_name, gate)

get(flag_name)

put(flag_name, gate)

worker_spec()