class Flagship::Dsl

Attributes

flagset[R]

Public Class Methods

new(key, context, base = nil, &block) click to toggle source
# 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

Public Instance Methods

disable(key, opts = {}) click to toggle source
# 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) click to toggle source
# File lib/flagship/dsl.rb, line 61
def disabled?(key)
  @flagset.disabled?(key)
end
enable(key, opts = {}) click to toggle source
# File lib/flagship/dsl.rb, line 26
def enable(key, opts = {})
  tags = opts.dup
  condition = tags.delete(:if)
  # convert to proc
  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) click to toggle source
# File lib/flagship/dsl.rb, line 57
def enabled?(key)
  @flagset.enabled?(key)
end
include(mod) click to toggle source
# File lib/flagship/dsl.rb, line 65
def include(mod)
  extend mod
end
with_tags(tags, &block) click to toggle source
# 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