Module: Flipper
- Defined in:
- 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/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/memoizable.rb,
lib/flipper/middleware/memoizer.rb,
lib/flipper/instrumenters/memory.rb,
lib/flipper/adapters/instrumented.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,
lib/flipper/instrumentation/metriks_subscriber.rb
Defined Under Namespace
Modules: Adapter, Adapters, Gates, Instrumentation, Instrumenters, Middleware, Test, Typecast, Types Classes: DSL, DuplicateGroup, Error, Feature, Gate, GateNotFound, GateValues, GroupNotRegistered, Registry, Type
Constant Summary collapse
- InstrumentationNamespace =
Private: The namespace for all instrumented events.
:flipper
- VERSION =
"0.9.0".freeze
Class Method Summary collapse
-
.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.
-
.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.
Class Method Details
.group(name) ⇒ Object
Public: Fetches a group by name.
name - The Symbol name of the group.
Examples
Flipper.group(:admins)
Returns the Flipper::Group if group registered. Raises Flipper::GroupNotRegistered if group is not registered.
69 70 71 72 73 |
# File 'lib/flipper.rb', line 69 def self.group(name) groups_registry.get(name) rescue Registry::KeyNotFound => e raise GroupNotRegistered, "Group #{e.key.inspect} has not been registered" end |
.group_exists?(name) ⇒ Boolean
Public: Check if a group exists
Returns boolean
55 56 57 |
# File 'lib/flipper.rb', line 55 def self.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)`.
41 42 43 |
# File 'lib/flipper.rb', line 41 def self.group_names groups_registry.keys.to_set end |
.groups ⇒ Object
Public: Returns a Set of registered Types::Group instances.
34 35 36 |
# File 'lib/flipper.rb', line 34 def self.groups groups_registry.values.to_set end |
.groups_registry ⇒ Object
Internal: Registry of all groups_registry.
76 77 78 |
# File 'lib/flipper.rb', line 76 def self.groups_registry @groups_registry ||= Registry.new end |
.groups_registry=(registry) ⇒ Object
Internal: Change the groups_registry registry.
81 82 83 |
# File 'lib/flipper.rb', line 81 def self.groups_registry=(registry) @groups_registry = registry 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.
7 8 9 |
# File 'lib/flipper.rb', line 7 def self.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.
25 26 27 28 29 30 31 |
# File 'lib/flipper.rb', line 25 def self.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.
48 49 50 |
# File 'lib/flipper.rb', line 48 def self.unregister_groups groups_registry.clear end |