Class: Flipper::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/flipper/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
# File 'lib/flipper/dsl.rb', line 17

def initialize(adapter, options = {})
  @instrumenter = options.fetch(:instrumenter, Flipper::Instrumenters::Noop)
  @adapter = Adapter.wrap(adapter, :instrumenter => @instrumenter)
  @memoized_features = {}
end

Instance Attribute Details

#adapterObject (readonly)

Private



7
8
9
# File 'lib/flipper/dsl.rb', line 7

def adapter
  @adapter
end

#instrumenterObject (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 not wrappable.



87
88
89
# File 'lib/flipper/dsl.rb', line 87

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.



106
107
108
# File 'lib/flipper/dsl.rb', line 106

def actors(number)
  Types::PercentageOfActors.new(number)
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.



49
50
51
# File 'lib/flipper/dsl.rb', line 49

def disable(name, *args)
  feature(name).disable(*args)
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.



39
40
41
# File 'lib/flipper/dsl.rb', line 39

def enable(name, *args)
  feature(name).enable(*args)
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.

Returns:

  • (Boolean)


29
30
31
# File 'lib/flipper/dsl.rb', line 29

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.



58
59
60
61
62
# File 'lib/flipper/dsl.rb', line 58

def feature(name)
  @memoized_features[name.to_sym] ||= Feature.new(name, @adapter, {
    :instrumenter => instrumenter,
  })
end

#featuresObject

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

Returns Set of Flipper::Feature instances.



114
115
116
# File 'lib/flipper/dsl.rb', line 114

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.



77
78
79
# File 'lib/flipper/dsl.rb', line 77

def group(name)
  Flipper.group(name)
end

#random(number) ⇒ Object Also known as: percentage_of_random

Public: Shortcut for getting a percentage of random instance.

number - The percentage of random that should be enabled.

Returns Flipper::Types::PercentageOfRandom.



96
97
98
# File 'lib/flipper/dsl.rb', line 96

def random(number)
  Types::PercentageOfRandom.new(number)
end