Class: Checkoff::SelectorEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/checkoff/internal/selector_evaluator.rb,
sig/checkoff.rbs

Overview

Base class to evaluate Asana resource selectors against an Asana resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#itemAsana::Resources::Resource (readonly)



65
66
67
# File 'lib/checkoff/internal/selector_evaluator.rb', line 65

def item
  @item
end

Instance Method Details

#evaluate(selector) ⇒ bool, ...

@param selector

Parameters:

  • selector (Symbol, ::Array[(Symbol | Integer | ::Array[untyped])])

Returns:

  • (bool, Object, ::Array[untyped], nil)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/checkoff/internal/selector_evaluator.rb', line 9

def evaluate(selector)
  return true if selector.empty?

  function_evaluators.each do |evaluator_class|
    # @type [Checkoff::SelectorClasses::FunctionEvaluator]
    evaluator = evaluator_class.new(selector:,
                                    **initializer_kwargs)

    next unless evaluator.matches?

    return try_this_evaluator(selector, evaluator)
  end

  raise "Syntax issue trying to handle #{selector.inspect}"
end

#evaluate_args(selector, evaluator) ⇒ ::Array[untyped]

@param selector

@param evaluator

Parameters:

Returns:

  • (::Array[untyped])


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/checkoff/internal/selector_evaluator.rb', line 41

def evaluate_args(selector, evaluator)
  return [] unless selector.is_a?(Array)

  # @sg-ignore Array#[] with an open-ended range is inferred as nilable even though it never is here
  selector[1..].map.with_index do |item, index|
    if evaluator.evaluate_arg?(index)
      evaluate(item)
    else
      item
    end
  end
end

#function_evaluators::Array[singleton(Checkoff::SelectorClasses::FunctionEvaluator)]

@sg-ignore abstract method always raises; declared type documents the override contract, not this body

Returns:



34
35
36
# File 'lib/checkoff/internal/selector_evaluator.rb', line 34

def function_evaluators
  raise 'Implement me!'
end

#initializer_kwargsHash

Returns:

  • (Hash)


28
29
30
# File 'lib/checkoff/internal/selector_evaluator.rb', line 28

def initializer_kwargs
  {}
end

#try_this_evaluator(selector, evaluator) ⇒ bool, ...

@param selector

@param evaluator

Parameters:

Returns:

  • (bool, Object, nil)


57
58
59
60
61
62
# File 'lib/checkoff/internal/selector_evaluator.rb', line 57

def try_this_evaluator(selector, evaluator)
  # if selector is an array
  evaluated_args = evaluate_args(selector, evaluator)

  evaluator.evaluate(item, *evaluated_args)
end