lib/checkoff/internal/task_selector_evaluator.rb in checkoff-0.29.4 vs lib/checkoff/internal/task_selector_evaluator.rb in checkoff-0.30.0

- old
+ new

@@ -33,10 +33,39 @@ matched_custom_field end attr_reader :task_selector + + def pull_enum_values(custom_field) + resource_subtype = custom_field.fetch('resource_subtype') + case resource_subtype + when 'enum' + [custom_field.fetch('enum_value')] + when 'multi_enum' + custom_field.fetch('multi_enum_values') + else + raise "Teach me how to handle resource_subtype #{resource_subtype}" + end + end + + def find_gids(custom_field, enum_value) + if enum_value.nil? + [] + else + raise "Unexpected enabled value on custom field: #{custom_field}" if enum_value.fetch('enabled') == false + + [enum_value.fetch('gid')] + end + end + + def pull_custom_field_values_gids(task, custom_field_gid) + custom_field = pull_custom_field_or_raise(task, custom_field_gid) + pull_enum_values(custom_field).flat_map do |enum_value| + find_gids(custom_field, enum_value) + end + end end # :and function class AndFunctionEvaluator < FunctionEvaluator def matches? @@ -150,41 +179,29 @@ actual_custom_field_values_gids.any? do |custom_field_value| custom_field_values_gids.include?(custom_field_value) end end + end - private + # :custom_field_gid_value_contains_all_gids function + class CustomFieldGidValueContainsAllGidsFunctionEvaluator < FunctionEvaluator + def matches? + fn?(task_selector, :custom_field_gid_value_contains_all_gids) + end - def pull_enum_values(custom_field) - resource_subtype = custom_field.fetch('resource_subtype') - case resource_subtype - when 'enum' - [custom_field.fetch('enum_value')] - when 'multi_enum' - custom_field.fetch('multi_enum_values') - else - raise "Teach me how to handle resource_subtype #{resource_subtype}" - end + def evaluate_arg?(_index) + false end - def find_gids(custom_field, enum_value) - if enum_value.nil? - [] - else - raise "Unexpected enabled value on custom field: #{custom_field}" if enum_value.fetch('enabled') == false + def evaluate(task, custom_field_gid, custom_field_values_gids) + actual_custom_field_values_gids = pull_custom_field_values_gids(task, custom_field_gid) - [enum_value.fetch('gid')] + custom_field_values_gids.all? do |custom_field_value| + actual_custom_field_values_gids.include?(custom_field_value) end end - - def pull_custom_field_values_gids(task, custom_field_gid) - custom_field = pull_custom_field_or_raise(task, custom_field_gid) - pull_enum_values(custom_field).flat_map do |enum_value| - find_gids(custom_field, enum_value) - end - end end # Evaluator task selectors against a task class TaskSelectorEvaluator def initialize(task:, @@ -198,9 +215,10 @@ NilPFunctionEvaluator, TagPFunctionEvaluator, CustomFieldValueFunctionEvaluator, CustomFieldGidValueFunctionEvaluator, CustomFieldGidValueContainsAnyGidFunctionEvaluator, + CustomFieldGidValueContainsAllGidsFunctionEvaluator, AndFunctionEvaluator, DuePFunctionEvaluator, ].freeze def evaluate(task_selector)