lib/checkoff/internal/task_selector_evaluator.rb in checkoff-0.28.0 vs lib/checkoff/internal/task_selector_evaluator.rb in checkoff-0.29.0
- old
+ new
@@ -1,12 +1,14 @@
# frozen_string_literal: true
module Checkoff
# Base class to evaluate a task selector function given fully evaluated arguments
class FunctionEvaluator
- def initialize(task_selector:)
+ def initialize(task_selector:,
+ tasks:)
@task_selector = task_selector
+ @tasks = tasks
end
def evaluate_arg?(_index)
true
end
@@ -81,10 +83,21 @@
def evaluate(task, tag_name)
task.tags.map(&:name).include? tag_name
end
end
+ # :due function
+ class DuePFunctionEvaluator < FunctionEvaluator
+ def matches?
+ fn?(task_selector, :due)
+ end
+
+ def evaluate(task)
+ @tasks.task_ready?(task)
+ end
+ end
+
# :custom_field_value function
class CustomFieldValueFunctionEvaluator < FunctionEvaluator
def matches?
fn?(task_selector, :custom_field_value)
end
@@ -172,29 +185,33 @@
end
end
# Evaluator task selectors against a task
class TaskSelectorEvaluator
- def initialize(task:)
+ def initialize(task:,
+ tasks: Checkoff::Tasks.new)
@task = task
+ @tasks = tasks
end
FUNCTION_EVALUTORS = [
NotFunctionEvaluator,
NilPFunctionEvaluator,
TagPFunctionEvaluator,
CustomFieldValueFunctionEvaluator,
CustomFieldGidValueFunctionEvaluator,
CustomFieldGidValueContainsAnyGidFunctionEvaluator,
AndFunctionEvaluator,
+ DuePFunctionEvaluator,
].freeze
def evaluate(task_selector)
return true if task_selector == []
FUNCTION_EVALUTORS.each do |evaluator_class|
- evaluator = evaluator_class.new(task_selector: task_selector)
+ evaluator = evaluator_class.new(task_selector: task_selector,
+ tasks: tasks)
next unless evaluator.matches?
return try_this_evaluator(task_selector, evaluator)
end
@@ -214,8 +231,8 @@
end
evaluator.evaluate(task, *evaluated_args)
end
- attr_reader :task, :task_selector
+ attr_reader :task, :tasks, :task_selector
end
end