Module: Corral::Helpers

Defined in:
lib/corral.rb

Instance Method Summary collapse

Instance Method Details

#corral(&block) ⇒ Object



24
25
26
# File 'lib/corral.rb', line 24

def corral(&block)
  instance_eval(&block)
end

#disable(feature, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/corral.rb', line 43

def disable(feature, options = {})
  condition = options[:when] || options[:if]

  if condition && !condition.respond_to?(:call)
    raise "'when' or 'if' condition must be a callable object"
  end

  Feature.push(feature, condition)
end

#disabled?(feature, argument = nil) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/corral.rb', line 28

def disabled?(feature, argument = nil)
  !enabled?(feature, argument)
end

#enabled?(feature, argument = nil) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
# File 'lib/corral.rb', line 32

def enabled?(feature, argument = nil)
  feature = Feature.get(feature)
  return false unless feature && (condition = feature.condition)

  if argument
    !condition.call(argument)
  else
    !condition.call
  end
end