Class: Flipper::DSL
- Inherits:
-
Object
- Object
- Flipper::DSL
- 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
-
#actor(thing) ⇒ Object
Public: Wraps an object as a flipper actor.
-
#actors(number) ⇒ Object
(also: #percentage_of_actors)
Public: Shortcut for getting a percentage of actors instance.
-
#add(name) ⇒ Object
Public: Add a feature.
-
#boolean(value = true) ⇒ Object
(also: #bool)
Public: Shortcut for getting a boolean type instance.
-
#disable(name, *args) ⇒ Object
Public: Disable a feature.
-
#disable_actor(name, actor) ⇒ Object
Public: Disable a feature for an actor.
-
#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_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.
-
#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.
- #import(flipper) ⇒ Object
-
#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.
-
#remove(name) ⇒ Object
Public: Remove a feature.
-
#time(number) ⇒ Object
(also: #percentage_of_time)
Public: Shortcut for getting a percentage of time instance.
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.
17 18 19 20 21 22 |
# File 'lib/flipper/dsl.rb', line 17 def initialize(adapter, = {}) @instrumenter = .fetch(:instrumenter, Instrumenters::Noop) memoized = Adapters::Memoizable.new(adapter) @adapter = memoized @memoized_features = {} end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Private
7 8 9 |
# File 'lib/flipper/dsl.rb', line 7 def adapter @adapter end |
#instrumenter ⇒ Object (readonly)
Private: What is being used to instrument all the things.
10 11 12 |
# File 'lib/flipper/dsl.rb', line 10 def instrumenter @instrumenter end |
Instance Method Details
#actor(thing) ⇒ Object
Public: Wraps an object as a flipper actor.
thing - The object that you would like to wrap.
Returns an instance of Flipper::Types::Actor. Raises ArgumentError if thing does not respond to ‘flipper_id`.
230 231 232 |
# File 'lib/flipper/dsl.rb', line 230 def actor(thing) Types::Actor.new(thing) end |
#actors(number) ⇒ Object Also known as: percentage_of_actors
Public: Shortcut for getting a percentage of actors instance.
number - The percentage of actors that should be enabled.
Returns Flipper::Types::PercentageOfActors.
249 250 251 |
# File 'lib/flipper/dsl.rb', line 249 def actors(number) Types::PercentageOfActors.new(number) end |
#add(name) ⇒ Object
Public: Add a feature.
name - The String or Symbol name of the feature.
Returns result of add.
147 148 149 |
# File 'lib/flipper/dsl.rb', line 147 def add(name) feature(name).add end |
#boolean(value = true) ⇒ Object Also known as: bool
Public: Shortcut for getting a boolean type instance.
value - The true or false value for the boolean.
Returns a Flipper::Types::Boolean instance.
204 205 206 |
# File 'lib/flipper/dsl.rb', line 204 def boolean(value = true) Types::Boolean.new(value) 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.
94 95 96 |
# File 'lib/flipper/dsl.rb', line 94 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.
105 106 107 |
# File 'lib/flipper/dsl.rb', line 105 def disable_actor(name, actor) feature(name).disable_actor(actor) 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.
116 117 118 |
# File 'lib/flipper/dsl.rb', line 116 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.
138 139 140 |
# File 'lib/flipper/dsl.rb', line 138 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.
127 128 129 |
# File 'lib/flipper/dsl.rb', line 127 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.
40 41 42 |
# File 'lib/flipper/dsl.rb', line 40 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.
51 52 53 |
# File 'lib/flipper/dsl.rb', line 51 def enable_actor(name, actor) feature(name).enable_actor(actor) 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.
62 63 64 |
# File 'lib/flipper/dsl.rb', line 62 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.
84 85 86 |
# File 'lib/flipper/dsl.rb', line 84 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.
73 74 75 |
# File 'lib/flipper/dsl.rb', line 73 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.
30 31 32 |
# File 'lib/flipper/dsl.rb', line 30 def enabled?(name, *args) feature(name).enabled?(*args) 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.
165 166 167 168 169 170 171 |
# File 'lib/flipper/dsl.rb', line 165 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.
257 258 259 |
# File 'lib/flipper/dsl.rb', line 257 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.
220 221 222 |
# File 'lib/flipper/dsl.rb', line 220 def group(name) Flipper.group(name) end |
#import(flipper) ⇒ Object
261 262 263 |
# File 'lib/flipper/dsl.rb', line 261 def import(flipper) adapter.import(flipper.adapter) 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.
178 179 180 181 182 |
# File 'lib/flipper/dsl.rb', line 178 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.
187 188 189 190 |
# File 'lib/flipper/dsl.rb', line 187 def preload_all keys = @adapter.get_all.keys keys.map { |key| feature(key) } end |
#remove(name) ⇒ Object
Public: Remove a feature.
name - The String or Symbol name of the feature.
Returns result of remove.
156 157 158 |
# File 'lib/flipper/dsl.rb', line 156 def remove(name) feature(name).remove end |
#time(number) ⇒ Object Also known as: percentage_of_time
Public: Shortcut for getting a percentage of time instance.
number - The percentage of time that should be enabled.
Returns Flipper::Types::PercentageOfTime.
239 240 241 |
# File 'lib/flipper/dsl.rb', line 239 def time(number) Types::PercentageOfTime.new(number) end |