Class: Flagship::Dsl

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

Defined Under Namespace

Classes: InvalidOptionError

Instance Method Summary collapse

Constructor Details

#initialize(key, context, base = nil, &block) ⇒ Dsl

Returns a new instance of Dsl.



4
5
6
7
8
9
10
# File 'lib/flagship/dsl.rb', line 4

def initialize(key, context, base = nil, &block)
  @key = key
  @context = context
  @base = base
  @flags = {}
  @definition = block
end

Instance Method Details

#disable(key, opts = {}) ⇒ Object

Raises:



20
21
22
23
24
# File 'lib/flagship/dsl.rb', line 20

def disable(key, opts = {})
  raise InvalidOptionError.new("Option :if is not available for #disable") if opts[:if]

  @flags[key] = false
end

#enable(key, opts = {}) ⇒ Object



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

def enable(key, opts = {})
  if opts[:if]
    @flags[key] = opts[:if]
  else
    @flags[key] = true
  end
end

#flagsetObject



26
27
28
29
# File 'lib/flagship/dsl.rb', line 26

def flagset
  instance_eval(&@definition)
  ::Flagship::Flagset.new(@key, @flags, @context, @base)
end