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
-
#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.
-
#exist?(name) ⇒ Boolean
Public: Has a feature been added in the adapter.
-
#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.
20 21 22 23 24 25 |
# File 'lib/flipper/dsl.rb', line 20 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
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
#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`.
242 243 244 |
# File 'lib/flipper/dsl.rb', line 242 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.
261 262 263 |
# File 'lib/flipper/dsl.rb', line 261 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.
150 151 152 |
# File 'lib/flipper/dsl.rb', line 150 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.
216 217 218 |
# File 'lib/flipper/dsl.rb', line 216 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.
97 98 99 |
# File 'lib/flipper/dsl.rb', line 97 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.
108 109 110 |
# File 'lib/flipper/dsl.rb', line 108 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.
119 120 121 |
# File 'lib/flipper/dsl.rb', line 119 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.
141 142 143 |
# File 'lib/flipper/dsl.rb', line 141 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.
130 131 132 |
# File 'lib/flipper/dsl.rb', line 130 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.
43 44 45 |
# File 'lib/flipper/dsl.rb', line 43 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.
54 55 56 |
# File 'lib/flipper/dsl.rb', line 54 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.
65 66 67 |
# File 'lib/flipper/dsl.rb', line 65 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.
87 88 89 |
# File 'lib/flipper/dsl.rb', line 87 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.
76 77 78 |
# File 'lib/flipper/dsl.rb', line 76 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.
33 34 35 |
# File 'lib/flipper/dsl.rb', line 33 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.
159 160 161 |
# File 'lib/flipper/dsl.rb', line 159 def exist?(name) feature(name).exist? 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.
177 178 179 180 181 182 183 |
# File 'lib/flipper/dsl.rb', line 177 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.
269 270 271 |
# File 'lib/flipper/dsl.rb', line 269 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.
232 233 234 |
# File 'lib/flipper/dsl.rb', line 232 def group(name) Flipper.group(name) end |
#import(flipper) ⇒ Object
273 274 275 |
# File 'lib/flipper/dsl.rb', line 273 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.
190 191 192 193 194 |
# File 'lib/flipper/dsl.rb', line 190 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.
199 200 201 202 |
# File 'lib/flipper/dsl.rb', line 199 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.
168 169 170 |
# File 'lib/flipper/dsl.rb', line 168 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.
251 252 253 |
# File 'lib/flipper/dsl.rb', line 251 def time(number) Types::PercentageOfTime.new(number) end |