class Flipper::DSL

Attributes

adapter[R]

Private

instrumenter[R]

Private: What is being used to instrument all the things.

Public Class Methods

new(adapter, options = {}) click to toggle source

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.
# File lib/flipper/dsl.rb, line 20
def initialize(adapter, options = {})
  @instrumenter = options.fetch(:instrumenter, Instrumenters::Noop)
  memoized = Adapters::Memoizable.new(adapter)
  @adapter = memoized
  @memoized_features = {}
end

Public Instance Methods

[](name)

Public: Shortcut access to a feature instance by name.

name - The String or Symbol name of the feature.

Returns an instance of Flipper::Feature.

Alias for: feature
actor(thing) click to toggle source

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`.

# File lib/flipper/dsl.rb, line 242
def actor(thing)
  Types::Actor.new(thing)
end
actors(number) click to toggle source

Public: Shortcut for getting a percentage of actors instance.

number - The percentage of actors that should be enabled.

Returns Flipper::Types::PercentageOfActors.

# File lib/flipper/dsl.rb, line 261
def actors(number)
  Types::PercentageOfActors.new(number)
end
Also aliased as: percentage_of_actors
add(name) click to toggle source

Public: Add a feature.

name - The String or Symbol name of the feature.

Returns result of add.

# File lib/flipper/dsl.rb, line 150
def add(name)
  feature(name).add
end
bool(value = true)

Public: Even shorter shortcut for getting a boolean type instance.

value - The true or false value for the boolean.

Returns a Flipper::Types::Boolean instance.

Alias for: boolean
boolean(value = true) click to toggle source

Public: Shortcut for getting a boolean type instance.

value - The true or false value for the boolean.

Returns a Flipper::Types::Boolean instance.

# File lib/flipper/dsl.rb, line 216
def boolean(value = true)
  Types::Boolean.new(value)
end
Also aliased as: bool
disable(name, *args) click to toggle source

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.

# File lib/flipper/dsl.rb, line 97
def disable(name, *args)
  feature(name).disable(*args)
end
disable_actor(name, actor) click to toggle source

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.

# File lib/flipper/dsl.rb, line 108
def disable_actor(name, actor)
  feature(name).disable_actor(actor)
end
disable_group(name, group) click to toggle source

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.

# File lib/flipper/dsl.rb, line 119
def disable_group(name, group)
  feature(name).disable_group(group)
end
disable_percentage_of_actors(name) click to toggle source

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.

# 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) click to toggle source

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.

# File lib/flipper/dsl.rb, line 130
def disable_percentage_of_time(name)
  feature(name).disable_percentage_of_time
end
enable(name, *args) click to toggle source

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.

# File lib/flipper/dsl.rb, line 43
def enable(name, *args)
  feature(name).enable(*args)
end
enable_actor(name, actor) click to toggle source

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.

# File lib/flipper/dsl.rb, line 54
def enable_actor(name, actor)
  feature(name).enable_actor(actor)
end
enable_group(name, group) click to toggle source

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.

# File lib/flipper/dsl.rb, line 65
def enable_group(name, group)
  feature(name).enable_group(group)
end
enable_percentage_of_actors(name, percentage) click to toggle source

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.

# 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) click to toggle source

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.

# 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) click to toggle source

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.

# File lib/flipper/dsl.rb, line 33
def enabled?(name, *args)
  feature(name).enabled?(*args)
end
exist?(name) click to toggle source

Public: Has a feature been added in the adapter.

name - The String or Symbol name of the feature.

Returns true if added else false.

# File lib/flipper/dsl.rb, line 159
def exist?(name)
  feature(name).exist?
end
feature(name) click to toggle source

Public: Access a feature instance by name.

name - The String or Symbol name of the feature.

Returns an instance of Flipper::Feature.

# 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
Also aliased as: []
features() click to toggle source

Public: Returns a Set of the known features for this adapter.

Returns Set of Flipper::Feature instances.

# File lib/flipper/dsl.rb, line 269
def features
  adapter.features.map { |name| feature(name) }.to_set
end
group(name) click to toggle source

Public: Access a flipper group by name.

name - The String or Symbol name of the feature.

Returns an instance of Flipper::Group.

# File lib/flipper/dsl.rb, line 232
def group(name)
  Flipper.group(name)
end
import(flipper) click to toggle source
# File lib/flipper/dsl.rb, line 273
def import(flipper)
  adapter.import(flipper.adapter)
end
percentage_of_actors(number)
Alias for: actors
percentage_of_time(number)
Alias for: time
preload(names) click to toggle source

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.

# File lib/flipper/dsl.rb, line 190
def preload(names)
  features = names.map { |name| feature(name) }
  @adapter.get_multi(features)
  features
end
preload_all() click to toggle source

Public: Preload all the adapters features.

Returns an Array of Flipper::Feature.

# File lib/flipper/dsl.rb, line 199
def preload_all
  keys = @adapter.get_all.keys
  keys.map { |key| feature(key) }
end
remove(name) click to toggle source

Public: Remove a feature.

name - The String or Symbol name of the feature.

Returns result of remove.

# File lib/flipper/dsl.rb, line 168
def remove(name)
  feature(name).remove
end
sync() click to toggle source

Cloud DSL method that does nothing for open source version.

# File lib/flipper/dsl.rb, line 278
def sync
end
sync_secret() click to toggle source

Cloud DSL method that does nothing for open source version.

# File lib/flipper/dsl.rb, line 282
def sync_secret
end
time(number) click to toggle source

Public: Shortcut for getting a percentage of time instance.

number - The percentage of time that should be enabled.

Returns Flipper::Types::PercentageOfTime.

# File lib/flipper/dsl.rb, line 251
def time(number)
  Types::PercentageOfTime.new(number)
end
Also aliased as: percentage_of_time