Class: Flagship::Dsl
- Inherits:
-
Object
show all
- Defined in:
- lib/flagship/dsl.rb
Defined Under Namespace
Classes: InvalidOptionError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(key, context, base = nil, &block) ⇒ Dsl
Returns a new instance of Dsl.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/flagship/dsl.rb', line 6
def initialize(key, context, base = nil, &block)
@key = key
@context = context
@base = base
@features = {}
@definition = block
@base_tags = {}
if @base
@base.helper_methods.each do |method|
define_singleton_method(method.name, &method)
end
end
instance_eval(&@definition)
helper_methods = singleton_methods.map { |sym| method(sym) }
@flagset = ::Flagship::Flagset.new(@key, @features, @base, helper_methods)
end
|
Instance Attribute Details
#flagset ⇒ Object
Returns the value of attribute flagset.
4
5
6
|
# File 'lib/flagship/dsl.rb', line 4
def flagset
@flagset
end
|
Instance Method Details
#disable(key, opts = {}) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/flagship/dsl.rb', line 42
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
|
#disabled?(key) ⇒ Boolean
61
62
63
|
# File 'lib/flagship/dsl.rb', line 61
def disabled?(key)
@flagset.disabled?(key)
end
|
#enable(key, opts = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/flagship/dsl.rb', line 26
def enable(key, opts = {})
tags = opts.dup
condition = tags.delete(:if)
if condition.is_a?(Symbol)
sym = condition
condition = ->(context) { method(sym).call(context) }
end
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
|
#enabled?(key) ⇒ Boolean
57
58
59
|
# File 'lib/flagship/dsl.rb', line 57
def enabled?(key)
@flagset.enabled?(key)
end
|
#include(mod) ⇒ Object
65
66
67
|
# File 'lib/flagship/dsl.rb', line 65
def include(mod)
extend mod
end
|
49
50
51
52
53
54
55
|
# File 'lib/flagship/dsl.rb', line 49
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
|