Module: Flipper
- Extended by:
- Flipper, Forwardable
- Included in:
- Flipper
- Defined in:
- lib/flipper/actor.rb,
lib/flipper.rb,
lib/flipper/cli.rb,
lib/flipper/dsl.rb,
lib/flipper/gate.rb,
lib/flipper/type.rb,
lib/flipper/cloud.rb,
lib/flipper/engine.rb,
lib/flipper/errors.rb,
lib/flipper/export.rb,
lib/flipper/poller.rb,
lib/flipper/adapter.rb,
lib/flipper/feature.rb,
lib/flipper/version.rb,
lib/flipper/exporter.rb,
lib/flipper/metadata.rb,
lib/flipper/registry.rb,
lib/flipper/typecast.rb,
lib/flipper/cloud/dsl.rb,
lib/flipper/test_help.rb,
lib/flipper/expression.rb,
lib/flipper/identifier.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/adapters/poll.rb,
lib/flipper/adapters/sync.rb,
lib/flipper/configuration.rb,
lib/flipper/gates/boolean.rb,
lib/flipper/types/boolean.rb,
lib/flipper/adapter_builder.rb,
lib/flipper/adapters/memory.rb,
lib/flipper/adapters/pstore.rb,
lib/flipper/adapters/strict.rb,
lib/flipper/cloud/telemetry.rb,
lib/flipper/expressions/all.rb,
lib/flipper/expressions/any.rb,
lib/flipper/expressions/now.rb,
lib/flipper/adapters/wrapper.rb,
lib/flipper/cloud/middleware.rb,
lib/flipper/expressions/time.rb,
lib/flipper/gates/expression.rb,
lib/flipper/serializers/gzip.rb,
lib/flipper/serializers/json.rb,
lib/flipper/types/percentage.rb,
lib/flipper/adapters/failover.rb,
lib/flipper/adapters/failsafe.rb,
lib/flipper/exporters/json/v1.rb,
lib/flipper/expressions/equal.rb,
lib/flipper/adapters/read_only.rb,
lib/flipper/expression/builder.rb,
lib/flipper/expressions/number.rb,
lib/flipper/expressions/random.rb,
lib/flipper/expressions/string.rb,
lib/flipper/instrumenters/noop.rb,
lib/flipper/adapters/cache_base.rb,
lib/flipper/adapters/dual_write.rb,
lib/flipper/adapters/http/error.rb,
lib/flipper/adapters/memoizable.rb,
lib/flipper/cloud/configuration.rb,
lib/flipper/expression/constant.rb,
lib/flipper/expressions/boolean.rb,
lib/flipper/middleware/memoizer.rb,
lib/flipper/model/active_record.rb,
lib/flipper/adapters/actor_limit.rb,
lib/flipper/adapters/http/client.rb,
lib/flipper/expressions/duration.rb,
lib/flipper/expressions/property.rb,
lib/flipper/instrumenters/memory.rb,
lib/flipper/middleware/setup_env.rb,
lib/flipper/adapters/instrumented.rb,
lib/flipper/exporters/json/export.rb,
lib/flipper/expressions/less_than.rb,
lib/flipper/expressions/not_equal.rb,
lib/flipper/feature_check_context.rb,
lib/flipper/cloud/message_verifier.rb,
lib/flipper/cloud/telemetry/metric.rb,
lib/flipper/expressions/comparable.rb,
lib/flipper/expressions/percentage.rb,
lib/flipper/expressions/greater_than.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/cloud/telemetry/submitter.rb,
lib/flipper/adapters/sync/synchronizer.rb,
lib/flipper/gates/percentage_of_actors.rb,
lib/flipper/instrumentation/subscriber.rb,
lib/flipper/types/percentage_of_actors.rb,
lib/generators/flipper/setup_generator.rb,
lib/generators/flipper/update_generator.rb,
lib/flipper/cloud/telemetry/instrumenter.rb,
lib/flipper/cloud/telemetry/backoff_policy.rb,
lib/flipper/cloud/telemetry/metric_storage.rb,
lib/flipper/instrumentation/log_subscriber.rb,
lib/flipper/expressions/percentage_of_actors.rb,
lib/flipper/expressions/less_than_or_equal_to.rb,
lib/flipper/instrumentation/statsd_subscriber.rb,
lib/flipper/adapters/sync/feature_synchronizer.rb,
lib/flipper/adapters/sync/interval_synchronizer.rb,
lib/flipper/expressions/greater_than_or_equal_to.rb
Overview
Simple class for turning a flipper_id into an actor that can be based to Flipper::Feature#enabled?.
Defined Under Namespace
Modules: Adapter, Adapters, Cloud, Exporter, Exporters, Expressions, Gates, Generators, Identifier, Instrumentation, Instrumenters, Middleware, Model, Serializers, Test, TestHelp, Types Classes: Actor, AdapterBuilder, CLI, Configuration, DSL, DuplicateGroup, Engine, Error, Export, Expression, Feature, FeatureCheckContext, Gate, GateNotFound, GateValues, InvalidConfigurationValue, Poller, Registry, Type, Typecast
Constant Summary collapse
- InstrumentationNamespace =
Private: The namespace for all instrumented events.
:flipper
- VERSION =
'1.3.1'.freeze
- REQUIRED_RUBY_VERSION =
'2.6'.freeze
- NEXT_REQUIRED_RUBY_VERSION =
'3.0'.freeze
- REQUIRED_RAILS_VERSION =
'5.2'.freeze
- NEXT_REQUIRED_RAILS_VERSION =
'6.1.0'.freeze
- METADATA =
{ "documentation_uri" => "https://www.flippercloud.io/docs", "homepage_uri" => "https://www.flippercloud.io", "source_code_uri" => "https://github.com/flippercloud/flipper", "bug_tracker_uri" => "https://github.com/flippercloud/flipper/issues", "changelog_uri" => "https://github.com/flippercloud/flipper/releases/tag/v#{Flipper::VERSION}", }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #all(*args) ⇒ Object
- #any(*args) ⇒ Object
- #boolean(value) ⇒ Object
-
#configuration ⇒ Object
Public: Returns Flipper::Configuration instance.
-
#configuration=(configuration) ⇒ Object
Public: Sets Flipper::Configuration instance.
-
#configure {|configuration| ... } ⇒ Object
Public: Configure flipper.
- #constant(value) ⇒ Object
-
#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.
- #number(value) ⇒ Object
- #property(name) ⇒ Object
- #random(max) ⇒ Object
-
#register(name, &block) ⇒ Object
Public: Use this to register a group by name.
- #string(value) ⇒ Object
-
#unregister_groups ⇒ Object
Public: Clears the group registry.
Class Method Details
.deprecated_ruby_version? ⇒ Boolean
10 11 12 |
# File 'lib/flipper/version.rb', line 10 def self.deprecated_ruby_version? Gem::Version.new(RUBY_VERSION) < Gem::Version.new(NEXT_REQUIRED_RUBY_VERSION) end |
Instance Method Details
#all(*args) ⇒ Object
75 76 77 |
# File 'lib/flipper.rb', line 75 def all(*args) Expression.build({ All: args.flatten }) end |
#any(*args) ⇒ Object
71 72 73 |
# File 'lib/flipper.rb', line 71 def any(*args) Expression.build({ Any: args.flatten }) end |
#boolean(value) ⇒ Object
95 96 97 |
# File 'lib/flipper.rb', line 95 def boolean(value) Expression.build({ Boolean: value }) end |
#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.adapter { ... }
end
Yields Flipper::Configuration instance.
23 24 25 |
# File 'lib/flipper.rb', line 23 def configure yield configuration if block_given? end |
#constant(value) ⇒ Object
79 80 81 |
# File 'lib/flipper.rb', line 79 def constant(value) Expression.build(value) end |
#group(name) ⇒ Object
Public: Fetches a group by name.
name - The Symbol name of the group.
Examples
Flipper.group(:admins)
Returns Flipper::Group.
160 161 162 |
# File 'lib/flipper.rb', line 160 def group(name) groups_registry.get(name) || Types::Group.new(name) end |
#group_exists?(name) ⇒ Boolean
Public: Check if a group exists
Returns boolean
147 148 149 |
# File 'lib/flipper.rb', line 147 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)`.
133 134 135 |
# File 'lib/flipper.rb', line 133 def group_names groups_registry.keys.to_set end |
#groups ⇒ Object
Public: Returns a Set of registered Types::Group instances.
126 127 128 |
# File 'lib/flipper.rb', line 126 def groups groups_registry.values.to_set end |
#groups_registry ⇒ Object
Internal: Registry of all groups_registry.
165 166 167 |
# File 'lib/flipper.rb', line 165 def groups_registry @groups_registry ||= Registry.new end |
#groups_registry=(registry) ⇒ Object
Internal: Change the groups_registry registry.
170 171 172 |
# File 'lib/flipper.rb', line 170 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 |
#number(value) ⇒ Object
91 92 93 |
# File 'lib/flipper.rb', line 91 def number(value) Expression.build({ Number: value }) end |
#property(name) ⇒ Object
83 84 85 |
# File 'lib/flipper.rb', line 83 def property(name) Expression.build({ Property: name }) end |
#random(max) ⇒ Object
99 100 101 |
# File 'lib/flipper.rb', line 99 def random(max) Expression.build({ Random: max }) 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 actor.
Examples
Flipper.register(:admins) { |actor|
actor.respond_to?(:admin?) && actor.admin?
}
Returns a Flipper::Group. Raises Flipper::DuplicateGroup if the group is already registered.
117 118 119 120 121 122 123 |
# File 'lib/flipper.rb', line 117 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 |
#string(value) ⇒ Object
87 88 89 |
# File 'lib/flipper.rb', line 87 def string(value) Expression.build({ String: value }) end |
#unregister_groups ⇒ Object
Public: Clears the group registry.
Returns nothing.
140 141 142 |
# File 'lib/flipper.rb', line 140 def unregister_groups groups_registry.clear end |