Class: Flipper::DSL
- Inherits:
-
Object
- Object
- Flipper::DSL
- Extended by:
- Forwardable
- Defined in:
- lib/flipper/dsl.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Private.
-
#instrumenter ⇒ Object
readonly
Private: What is being used to instrument all the things.
Instance Method Summary collapse
-
#add(name) ⇒ Object
Public: Add a feature.
-
#add_expression(name, expression) ⇒ Object
Public: Add an expression to a feature.
-
#disable(name, *args) ⇒ Object
Public: Disable a feature.
-
#disable_actor(name, actor) ⇒ Object
Public: Disable a feature for an actor.
-
#disable_expression(name) ⇒ Object
Public: Disable expression for feature.
-
#disable_group(name, group) ⇒ Object
Public: Disable a feature for a group.
-
#disable_percentage_of_actors(name) ⇒ Object
Public: Disable a feature for a percentage of actors.
-
#disable_percentage_of_time(name) ⇒ Object
Public: Disable a feature a percentage of time.
-
#enable(name, *args) ⇒ Object
Public: Enable a feature.
-
#enable_actor(name, actor) ⇒ Object
Public: Enable a feature for an actor.
-
#enable_expression(name, expression) ⇒ Object
Public: Enable a feature for an expression.
-
#enable_group(name, group) ⇒ Object
Public: Enable a feature for a group.
-
#enable_percentage_of_actors(name, percentage) ⇒ Object
Public: Enable a feature for a percentage of actors.
-
#enable_percentage_of_time(name, percentage) ⇒ Object
Public: Enable a feature a percentage of time.
-
#enabled?(name, *args) ⇒ Boolean
Public: Check if a feature is enabled.
-
#exist?(name) ⇒ Boolean
Public: Has a feature been added in the adapter.
-
#expression(name) ⇒ Object
Public: Gets the expression for the feature.
-
#feature(name) ⇒ Object
(also: #[])
Public: Access a feature instance by name.
-
#features ⇒ Object
Public: Returns a Set of the known features for this adapter.
-
#group(name) ⇒ Object
Public: Access a flipper group by name.
-
#initialize(adapter, options = {}) ⇒ DSL
constructor
Public: Returns a new instance of the DSL.
-
#preload(names) ⇒ Object
Public: Preload the features with the given names.
-
#preload_all ⇒ Object
Public: Preload all the adapters features.
-
#read_only? ⇒ Boolean
Public: Does this adapter support writes or not.
-
#remove(name) ⇒ Object
Public: Remove a feature.
-
#remove_expression(name, expression) ⇒ Object
Public: Remove an expression from a feature.
-
#sync ⇒ Object
Cloud DSL method that does nothing for open source version.
-
#sync_secret ⇒ Object
Cloud DSL method that does nothing for open source version.
Constructor Details
#initialize(adapter, options = {}) ⇒ DSL
Public: Returns a new instance of the DSL.
adapter - The adapter that this DSL instance should use. options - The Hash of options.
:instrumenter - What should be used to instrument all the things.
:memoize - Should adapter be wrapped by memoize adapter or not.
21 22 23 24 25 26 27 |
# File 'lib/flipper/dsl.rb', line 21 def initialize(adapter, = {}) @instrumenter = .fetch(:instrumenter, Instrumenters::Noop) memoize = .fetch(:memoize, true) adapter = Adapters::Memoizable.new(adapter) if memoize @adapter = adapter @memoized_features = {} end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Private
8 9 10 |
# File 'lib/flipper/dsl.rb', line 8 def adapter @adapter end |
#instrumenter ⇒ Object (readonly)
Private: What is being used to instrument all the things.
11 12 13 |
# File 'lib/flipper/dsl.rb', line 11 def instrumenter @instrumenter end |
Instance Method Details
#add(name) ⇒ Object
Public: Add a feature.
name - The String or Symbol name of the feature.
Returns result of add.
189 190 191 |
# File 'lib/flipper/dsl.rb', line 189 def add(name) feature(name).add end |
#add_expression(name, expression) ⇒ Object
Public: Add an expression to a feature.
expression - an expression or Hash that can be converted to an expression.
Returns result of enable.
64 65 66 |
# File 'lib/flipper/dsl.rb', line 64 def add_expression(name, expression) feature(name).add_expression(expression) end |
#disable(name, *args) ⇒ Object
Public: Disable a feature.
name - The String or Symbol name of the feature. args - The args passed through to the feature instance enable call.
Returns the result of the feature instance disable call.
118 119 120 |
# File 'lib/flipper/dsl.rb', line 118 def disable(name, *args) feature(name).disable(*args) end |
#disable_actor(name, actor) ⇒ Object
Public: Disable a feature for an actor.
name - The String or Symbol name of the feature. actor - a Flipper::Types::Actor instance or an object that responds
to flipper_id.
Returns result of disable.
147 148 149 |
# File 'lib/flipper/dsl.rb', line 147 def disable_actor(name, actor) feature(name).disable_actor(actor) end |
#disable_expression(name) ⇒ Object
Public: Disable expression for feature.
name - The String or Symbol name of the feature.
Returns result of Feature#disable.
127 128 129 |
# File 'lib/flipper/dsl.rb', line 127 def disable_expression(name) feature(name).disable_expression end |
#disable_group(name, group) ⇒ Object
Public: Disable a feature for a group.
name - The String or Symbol name of the feature. group - a Flipper::Types::Group instance or a String or Symbol name of a
registered group.
Returns result of disable.
158 159 160 |
# File 'lib/flipper/dsl.rb', line 158 def disable_group(name, group) feature(name).disable_group(group) end |
#disable_percentage_of_actors(name) ⇒ Object
Public: Disable a feature for a percentage of actors.
name - The String or Symbol name of the feature. percentage - a Flipper::Types::PercentageOfActors instance or an object
that responds to to_i.
Returns result of disable.
180 181 182 |
# File 'lib/flipper/dsl.rb', line 180 def disable_percentage_of_actors(name) feature(name).disable_percentage_of_actors end |
#disable_percentage_of_time(name) ⇒ Object
Public: Disable a feature a percentage of time.
name - The String or Symbol name of the feature. percentage - a Flipper::Types::PercentageOfTime instance or an object
that responds to to_i.
Returns result of disable.
169 170 171 |
# File 'lib/flipper/dsl.rb', line 169 def disable_percentage_of_time(name) feature(name).disable_percentage_of_time end |
#enable(name, *args) ⇒ Object
Public: Enable a feature.
name - The String or Symbol name of the feature. args - The args passed through to the feature instance enable call.
Returns the result of the feature instance enable call.
45 46 47 |
# File 'lib/flipper/dsl.rb', line 45 def enable(name, *args) feature(name).enable(*args) end |
#enable_actor(name, actor) ⇒ Object
Public: Enable a feature for an actor.
name - The String or Symbol name of the feature. actor - a Flipper::Types::Actor instance or an object that responds
to flipper_id.
Returns result of Feature#enable.
75 76 77 |
# File 'lib/flipper/dsl.rb', line 75 def enable_actor(name, actor) feature(name).enable_actor(actor) end |
#enable_expression(name, expression) ⇒ Object
Public: Enable a feature for an expression.
name - The String or Symbol name of the feature. expression - a Flipper::Expression instance or a Hash.
Returns result of Feature#enable.
55 56 57 |
# File 'lib/flipper/dsl.rb', line 55 def enable_expression(name, expression) feature(name).enable_expression(expression) end |
#enable_group(name, group) ⇒ Object
Public: Enable a feature for a group.
name - The String or Symbol name of the feature. group - a Flipper::Types::Group instance or a String or Symbol name of a
registered group.
Returns result of Feature#enable.
86 87 88 |
# File 'lib/flipper/dsl.rb', line 86 def enable_group(name, group) feature(name).enable_group(group) end |
#enable_percentage_of_actors(name, percentage) ⇒ Object
Public: Enable a feature for a percentage of actors.
name - The String or Symbol name of the feature. percentage - a Flipper::Types::PercentageOfActors instance or an object
that responds to to_i.
Returns result of Feature#enable.
108 109 110 |
# File 'lib/flipper/dsl.rb', line 108 def enable_percentage_of_actors(name, percentage) feature(name).enable_percentage_of_actors(percentage) end |
#enable_percentage_of_time(name, percentage) ⇒ Object
Public: Enable a feature a percentage of time.
name - The String or Symbol name of the feature. percentage - a Flipper::Types::PercentageOfTime instance or an object
that responds to to_i.
Returns result of Feature#enable.
97 98 99 |
# File 'lib/flipper/dsl.rb', line 97 def enable_percentage_of_time(name, percentage) feature(name).enable_percentage_of_time(percentage) end |
#enabled?(name, *args) ⇒ Boolean
Public: Check if a feature is enabled.
name - The String or Symbol name of the feature. args - The args passed through to the enabled check.
Returns true if feature is enabled, false if not.
35 36 37 |
# File 'lib/flipper/dsl.rb', line 35 def enabled?(name, *args) feature(name).enabled?(*args) end |
#exist?(name) ⇒ Boolean
Public: Has a feature been added in the adapter.
name - The String or Symbol name of the feature.
Returns true if added else false.
198 199 200 |
# File 'lib/flipper/dsl.rb', line 198 def exist?(name) feature(name).exist? end |
#expression(name) ⇒ Object
Public: Gets the expression for the feature.
name - The String or Symbol name of the feature.
Returns an instance of Flipper::Expression.
264 265 266 |
# File 'lib/flipper/dsl.rb', line 264 def expression(name) feature(name).expression end |
#feature(name) ⇒ Object Also known as: []
Public: Access a feature instance by name.
name - The String or Symbol name of the feature.
Returns an instance of Flipper::Feature.
216 217 218 219 220 221 222 |
# File 'lib/flipper/dsl.rb', line 216 def feature(name) if !name.is_a?(String) && !name.is_a?(Symbol) raise ArgumentError, "#{name} must be a String or Symbol" end @memoized_features[name.to_sym] ||= Feature.new(name, @adapter, instrumenter: instrumenter) end |
#features ⇒ Object
Public: Returns a Set of the known features for this adapter.
Returns Set of Flipper::Feature instances.
271 272 273 |
# File 'lib/flipper/dsl.rb', line 271 def features adapter.features.map { |name| feature(name) }.to_set end |
#group(name) ⇒ Object
Public: Access a flipper group by name.
name - The String or Symbol name of the feature.
Returns an instance of Flipper::Group.
255 256 257 |
# File 'lib/flipper/dsl.rb', line 255 def group(name) Flipper.group(name) end |
#preload(names) ⇒ Object
Public: Preload the features with the given names.
names - An Array of String or Symbol names of the features.
Returns an Array of Flipper::Feature.
229 230 231 232 233 |
# File 'lib/flipper/dsl.rb', line 229 def preload(names) features = names.map { |name| feature(name) } @adapter.get_multi(features) features end |
#preload_all ⇒ Object
Public: Preload all the adapters features.
Returns an Array of Flipper::Feature.
238 239 240 241 |
# File 'lib/flipper/dsl.rb', line 238 def preload_all keys = @adapter.get_all.keys keys.map { |key| feature(key) } end |
#read_only? ⇒ Boolean
Public: Does this adapter support writes or not.
276 277 278 |
# File 'lib/flipper/dsl.rb', line 276 def read_only? adapter.read_only? end |
#remove(name) ⇒ Object
Public: Remove a feature.
name - The String or Symbol name of the feature.
Returns result of remove.
207 208 209 |
# File 'lib/flipper/dsl.rb', line 207 def remove(name) feature(name).remove end |
#remove_expression(name, expression) ⇒ Object
Public: Remove an expression from a feature.
expression - an Expression or Hash that can be converted to an expression.
Returns result of enable.
136 137 138 |
# File 'lib/flipper/dsl.rb', line 136 def remove_expression(name, expression) feature(name).remove_expression(expression) end |
#sync ⇒ Object
Cloud DSL method that does nothing for open source version.
281 282 |
# File 'lib/flipper/dsl.rb', line 281 def sync end |
#sync_secret ⇒ Object
Cloud DSL method that does nothing for open source version.
285 286 |
# File 'lib/flipper/dsl.rb', line 285 def sync_secret end |