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) ⇒ Flagset

Returns a new instance of Flagset.



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

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

Instance Attribute Details

#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

#enabled?(key) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



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

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


  @features[key].enabled?
end

#featuresObject



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

def features
  @features.map { |key, feature| feature }
end