class Errapi::Condition

Constants

ALLOWED_CONDITIONALS

Public Class Methods

conditionals() click to toggle source
# File lib/errapi/condition.rb, line 4
def self.conditionals
  h = const_get('CONDITIONALS')
  raise LoadError, "The CONDITIONALS constant in class #{self} is of the wrong type (#{h.class}). Either make it a Hash or override #{self}.conditionals to return a list of symbols." unless h.kind_of? Hash
  h.keys
end
new(conditional, predicate, options = {}) click to toggle source
# File lib/errapi/condition.rb, line 10
def initialize conditional, predicate, options = {}

  @conditional = resolve_conditional conditional
  raise ArgumentError, "Conditional must be either :if or :unless" unless ALLOWED_CONDITIONALS.include? @conditional

  @predicate = predicate
end

Public Instance Methods

check(predicate, value, context, options = {}) click to toggle source
# File lib/errapi/condition.rb, line 28
def check predicate, value, context, options = {}
  raise NotImplementedError, "Subclasses should implement the #check method to check whether the value matches the predicate of the condition"
end
fulfilled?(*args) click to toggle source
# File lib/errapi/condition.rb, line 18
def fulfilled? *args
  result = check @predicate, *args
  result = !result if @conditional == :unless
  result
end
resolve_conditional(conditional) click to toggle source
# File lib/errapi/condition.rb, line 24
def resolve_conditional conditional
  conditional
end