Class: Flagship::Flagset

Inherits:
Object
  • Object
show all
Defined in:
lib/flagship/flagset.rb

Defined Under Namespace

Classes: UndefinedFlagError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, features_hash, base = nil, helper_methods = []) ⇒ Flagset

Returns a new instance of Flagset.



6
7
8
9
10
11
12
# File 'lib/flagship/flagset.rb', line 6

def initialize(key, features_hash, base = nil, helper_methods = [])
  @key = key
  @features = base ?
    extend_features(features_hash, base) :
    features_hash
  @helper_methods = helper_methods
end

Instance Attribute Details

#helper_methodsObject (readonly)

Returns the value of attribute helper_methods.



2
3
4
# File 'lib/flagship/flagset.rb', line 2

def helper_methods
  @helper_methods
end

#keyObject (readonly)

Returns the value of attribute key.



2
3
4
# File 'lib/flagship/flagset.rb', line 2

def key
  @key
end

Instance Method Details

#disabled?(key) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/flagship/flagset.rb', line 21

def disabled?(key)
  !enabled?(key)
end

#enabled?(key) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



14
15
16
17
18
19
# File 'lib/flagship/flagset.rb', line 14

def enabled?(key)
  raise UndefinedFlagError.new("The flag :#{key} is not defined") unless @features.key? key


  @features[key].enabled?
end

#featuresObject



25
26
27
# File 'lib/flagship/flagset.rb', line 25

def features
  Flagship::Features.new @features.map { |key, feature| feature }
end