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



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
  @features = {}
  @definition = block
end

Instance Method Details

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

Raises:



23
24
25
26
27
# File 'lib/flagship/dsl.rb', line 23

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

  @features[key] = ::Flagship::Feature.new(key, false, @context, opts)
end

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



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

def enable(key, opts = {})
  opts = opts.dup
  condition = opts.delete(:if)

  if condition
    @features[key] = ::Flagship::Feature.new(key, condition, @context, opts)
  else
    @features[key] = ::Flagship::Feature.new(key, true, @context, opts)
  end
end

#flagsetObject



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

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