Class: DecisionAgent::Dmn::Feel::Functions::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/decision_agent/dmn/feel/functions.rb

Overview

Base class for all functions

Class Method Summary collapse

Class Method Details

.call(args, context = {}) ⇒ Object

Execute function with arguments and context Returns either a value or a ConditionEvaluator condition structure

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/decision_agent/dmn/feel/functions.rb', line 27

def call(args, context = {})
  raise NotImplementedError, "Subclasses must implement call"
end

.register(*names) ⇒ Object

Register function with one or more names



21
22
23
# File 'lib/decision_agent/dmn/feel/functions.rb', line 21

def register(*names)
  names.each { |name| REGISTRY[name.to_s] = self }
end

.validate_arg_count(args, expected) ⇒ Object

Validate argument count

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/decision_agent/dmn/feel/functions.rb', line 32

def validate_arg_count(args, expected)
  actual = args.length
  valid = if expected.is_a?(Range)
            expected.cover?(actual)
          else
            actual == expected
          end

  return if valid

  raise FeelFunctionError, "Wrong number of arguments for #{name} (got #{actual}, expected #{expected})"
end