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
11
# File 'lib/flagship/dsl.rb', line 4

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

Instance Method Details

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

Raises:



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

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

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

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



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

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

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

#flagsetObject



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

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

#with_tags(tags, &block) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/flagship/dsl.rb', line 31

def with_tags(tags, &block)
  orig_base_tags = @base_tags
  @base_tags = @base_tags.merge(tags)
  instance_eval(&block)
ensure
  @base_tags = orig_base_tags
end