Module: Flipper
- Extended by:
- Flipper, Forwardable
- Included in:
- Flipper
- Defined in:
- lib/flipper/actor.rb,
lib/flipper.rb,
lib/flipper/dsl.rb,
lib/flipper/gate.rb,
lib/flipper/type.rb,
lib/flipper/errors.rb,
lib/flipper/adapter.rb,
lib/flipper/feature.rb,
lib/flipper/version.rb,
lib/flipper/registry.rb,
lib/flipper/typecast.rb,
lib/flipper/gate_values.rb,
lib/flipper/gates/actor.rb,
lib/flipper/gates/group.rb,
lib/flipper/types/actor.rb,
lib/flipper/types/group.rb,
lib/flipper/adapters/http.rb,
lib/flipper/configuration.rb,
lib/flipper/gates/boolean.rb,
lib/flipper/types/boolean.rb,
lib/flipper/adapters/memory.rb,
lib/flipper/adapters/pstore.rb,
lib/flipper/types/percentage.rb,
lib/flipper/adapters/read_only.rb,
lib/flipper/instrumenters/noop.rb,
lib/flipper/adapters/http/error.rb,
lib/flipper/adapters/memoizable.rb,
lib/flipper/middleware/memoizer.rb,
lib/flipper/adapters/http/client.rb,
lib/flipper/instrumenters/memory.rb,
lib/flipper/middleware/setup_env.rb,
lib/flipper/adapters/instrumented.rb,
lib/flipper/feature_check_context.rb,
lib/flipper/gates/percentage_of_time.rb,
lib/flipper/test/shared_adapter_test.rb,
lib/flipper/types/percentage_of_time.rb,
lib/flipper/adapters/operation_logger.rb,
lib/flipper/gates/percentage_of_actors.rb,
lib/flipper/instrumentation/subscriber.rb,
lib/flipper/types/percentage_of_actors.rb,
lib/flipper/instrumentation/log_subscriber.rb,
lib/flipper/instrumentation/statsd_subscriber.rb
Overview
rubocop:disable Metrics/ModuleLength
Defined Under Namespace
Modules: Adapter, Adapters, Gates, Instrumentation, Instrumenters, Middleware, Test, Typecast, Types Classes: Actor, Configuration, DSL, DefaultNotSet, DuplicateGroup, Error, Feature, FeatureCheckContext, Gate, GateNotFound, GateValues, Registry, Type
Constant Summary collapse
- InstrumentationNamespace =
Private: The namespace for all instrumented events.
:flipper
- VERSION =
'0.12.0'.freeze
Instance Method Summary collapse
-
#configuration ⇒ Object
Public: Returns Flipper::Configuration instance.
-
#configuration=(configuration) ⇒ Object
Public: Sets Flipper::Configuration instance.
-
#configure {|configuration| ... } ⇒ Object
Public: Configure flipper.
-
#group(name) ⇒ Object
Public: Fetches a group by name.
-
#group_exists?(name) ⇒ Boolean
Public: Check if a group exists.
-
#group_names ⇒ Object
Public: Returns a Set of symbols where each symbol is a registered group name.
-
#groups ⇒ Object
Public: Returns a Set of registered Types::Group instances.
-
#groups_registry ⇒ Object
Internal: Registry of all groups_registry.
-
#groups_registry=(registry) ⇒ Object
Internal: Change the groups_registry registry.
-
#instance ⇒ Object
Public: Default per thread flipper instance if configured.
-
#instance=(flipper) ⇒ Object
Public: Set the flipper instance.
-
#new(adapter, options = {}) ⇒ Object
Public: Start here.
-
#register(name, &block) ⇒ Object
Public: Use this to register a group by name.
-
#unregister_groups ⇒ Object
Public: Clears the group registry.
Instance Method Details
#configuration ⇒ Object
Public: Returns Flipper::Configuration instance.
28 29 30 |
# File 'lib/flipper.rb', line 28 def configuration @configuration ||= Configuration.new end |
#configuration=(configuration) ⇒ Object
Public: Sets Flipper::Configuration instance.
33 34 35 36 37 |
# File 'lib/flipper.rb', line 33 def configuration=(configuration) # need to reset flipper instance if configuration changes self.instance = nil @configuration = configuration end |
#configure {|configuration| ... } ⇒ Object
Public: Configure flipper.
Flipper.configure do |config|
config.default { ... }
end
Yields Flipper::Configuration instance.
23 24 25 |
# File 'lib/flipper.rb', line 23 def configure yield configuration if block_given? end |
#group(name) ⇒ Object
Public: Fetches a group by name.
name - The Symbol name of the group.
Examples
Flipper.group(:admins)
Returns Flipper::Group.
127 128 129 |
# File 'lib/flipper.rb', line 127 def group(name) groups_registry.get(name) || Types::Group.new(name) end |
#group_exists?(name) ⇒ Boolean
Public: Check if a group exists
Returns boolean
114 115 116 |
# File 'lib/flipper.rb', line 114 def group_exists?(name) groups_registry.key?(name) end |
#group_names ⇒ Object
Public: Returns a Set of symbols where each symbol is a registered group name. If you just want the names, this is more efficient than doing ‘Flipper.groups.map(&:name)`.
100 101 102 |
# File 'lib/flipper.rb', line 100 def group_names groups_registry.keys.to_set end |
#groups ⇒ Object
Public: Returns a Set of registered Types::Group instances.
93 94 95 |
# File 'lib/flipper.rb', line 93 def groups groups_registry.values.to_set end |
#groups_registry ⇒ Object
Internal: Registry of all groups_registry.
132 133 134 |
# File 'lib/flipper.rb', line 132 def groups_registry @groups_registry ||= Registry.new end |
#groups_registry=(registry) ⇒ Object
Internal: Change the groups_registry registry.
137 138 139 |
# File 'lib/flipper.rb', line 137 def groups_registry=(registry) @groups_registry = registry end |
#instance ⇒ Object
Public: Default per thread flipper instance if configured. You should not need to use this directly as most of the Flipper::DSL methods are delegated from Flipper module itself. Instead of doing Flipper.instance.enabled?(:search), you can use Flipper.enabled?(:search) for the same result.
Returns Flipper::DSL instance.
45 46 47 |
# File 'lib/flipper.rb', line 45 def instance Thread.current[:flipper_instance] ||= configuration.default end |
#instance=(flipper) ⇒ Object
Public: Set the flipper instance. It is most common to use the Configuration#default to set this instance, but for things like the test environment, this writer is actually useful.
52 53 54 |
# File 'lib/flipper.rb', line 52 def instance=(flipper) Thread.current[:flipper_instance] = flipper end |
#new(adapter, options = {}) ⇒ Object
Public: Start here. Given an adapter returns a handy DSL to all the flipper goodness. To see supported options, check out dsl.rb.
12 13 14 |
# File 'lib/flipper.rb', line 12 def new(adapter, = {}) DSL.new(adapter, ) end |
#register(name, &block) ⇒ Object
Public: Use this to register a group by name.
name - The Symbol name of the group. block - The block that should be used to determine if the group matches a
given thing.
Examples
Flipper.register(:admins) { |thing|
thing.respond_to?(:admin?) && thing.admin?
}
Returns a Flipper::Group. Raises Flipper::DuplicateGroup if the group is already registered.
84 85 86 87 88 89 90 |
# File 'lib/flipper.rb', line 84 def register(name, &block) group = Types::Group.new(name, &block) groups_registry.add(group.name, group) group rescue Registry::DuplicateKey raise DuplicateGroup, "Group #{name.inspect} has already been registered" end |
#unregister_groups ⇒ Object
Public: Clears the group registry.
Returns nothing.
107 108 109 |
# File 'lib/flipper.rb', line 107 def unregister_groups groups_registry.clear end |