Module: Philiprehberger::RuleEngine::Helpers

Included in:
Engine, Rule
Defined in:
lib/philiprehberger/rule_engine/helpers.rb

Overview

Composite condition helpers for readable logic in condition blocks.

Instance Method Summary collapse

Instance Method Details

#all?(*conditions) ⇒ Boolean

Returns true if all conditions are truthy.

Parameters:

  • conditions (Array<Boolean, Proc>)

    values or procs to evaluate

Returns:

  • (Boolean)


11
12
13
# File 'lib/philiprehberger/rule_engine/helpers.rb', line 11

def all?(*conditions)
  conditions.all? { |c| c.is_a?(Proc) ? c.call : c }
end

#any?(*conditions) ⇒ Boolean

Returns true if any condition is truthy.

Parameters:

  • conditions (Array<Boolean, Proc>)

    values or procs to evaluate

Returns:

  • (Boolean)


19
20
21
# File 'lib/philiprehberger/rule_engine/helpers.rb', line 19

def any?(*conditions)
  conditions.any? { |c| c.is_a?(Proc) ? c.call : c }
end

#none?(*conditions) ⇒ Boolean

Returns true if no conditions are truthy.

Parameters:

  • conditions (Array<Boolean, Proc>)

    values or procs to evaluate

Returns:

  • (Boolean)


27
28
29
# File 'lib/philiprehberger/rule_engine/helpers.rb', line 27

def none?(*conditions)
  conditions.none? { |c| c.is_a?(Proc) ? c.call : c }
end