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.
-
#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.
-
#initialize(adapter, options = {}) ⇒ DSL
constructor
Public: Returns a new instance of the DSL.
-
#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.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/flipper/dsl.rb', line 18 def initialize(adapter, = {}) @instrumenter = .fetch(:instrumenter, Instrumenters::Noop) instrumented = Adapters::Instrumented.new(adapter, { :instrumenter => @instrumenter, }) memoized = Adapters::Memoizable.new(instrumented) @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`.
202 203 204 |
# File 'lib/flipper/dsl.rb', line 202 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.
221 222 223 |
# File 'lib/flipper/dsl.rb', line 221 def actors(number) Types::PercentageOfActors.new(number) 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.
175 176 177 |
# File 'lib/flipper/dsl.rb', line 175 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.
100 101 102 |
# File 'lib/flipper/dsl.rb', line 100 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.
111 112 113 |
# File 'lib/flipper/dsl.rb', line 111 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.
122 123 124 |
# File 'lib/flipper/dsl.rb', line 122 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.
144 145 146 |
# File 'lib/flipper/dsl.rb', line 144 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.
133 134 135 |
# File 'lib/flipper/dsl.rb', line 133 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.
46 47 48 |
# File 'lib/flipper/dsl.rb', line 46 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.
57 58 59 |
# File 'lib/flipper/dsl.rb', line 57 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.
68 69 70 |
# File 'lib/flipper/dsl.rb', line 68 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.
90 91 92 |
# File 'lib/flipper/dsl.rb', line 90 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.
79 80 81 |
# File 'lib/flipper/dsl.rb', line 79 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.
36 37 38 |
# File 'lib/flipper/dsl.rb', line 36 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.
153 154 155 156 157 158 159 160 161 |
# File 'lib/flipper/dsl.rb', line 153 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.
229 230 231 |
# File 'lib/flipper/dsl.rb', line 229 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. Raises Flipper::GroupNotRegistered if group has not been registered.
192 193 194 |
# File 'lib/flipper/dsl.rb', line 192 def group(name) Flipper.group(name) 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.
211 212 213 |
# File 'lib/flipper/dsl.rb', line 211 def time(number) Types::PercentageOfTime.new(number) end |