lib/checkoff/internal/task_selector_evaluator.rb in checkoff-0.26.0 vs lib/checkoff/internal/task_selector_evaluator.rb in checkoff-0.26.1

- old
+ new

@@ -15,10 +15,25 @@ def fn?(object, fn_name) object.is_a?(Array) && !object.empty? && [fn_name, fn_name.to_s].include?(object[0]) end + def pull_custom_field_or_raise(task, custom_field_gid) + custom_fields = task.custom_fields + if custom_fields.nil? + raise "Could not find custom_fields under task (was 'custom_fields' included in 'extra_fields'?)" + end + + matched_custom_field = custom_fields.find { |data| data.fetch('gid') == custom_field_gid } + if matched_custom_field.nil? + raise "Could not find custom field with gid #{custom_field_gid} " \ + "in task #{task.gid} with custom fields #{custom_fields}" + end + + matched_custom_field + end + attr_reader :task_selector end # :and function class AndFunctionEvaluator < FunctionEvaluator @@ -89,10 +104,26 @@ custom_field['display_value'] end end + # :custom_field_gid_value function + class CustomFieldGidValueFunctionEvaluator < FunctionEvaluator + def matches? + fn?(task_selector, :custom_field_gid_value) + end + + def evaluate_arg?(_index) + false + end + + def evaluate(task, custom_field_gid) + custom_field = pull_custom_field_or_raise(task, custom_field_gid) + custom_field['display_value'] + end + end + # :custom_field_gid_value_contains_any_gid function class CustomFieldGidValueContainsAnyGidFunctionEvaluator < FunctionEvaluator def matches? fn?(task_selector, :custom_field_gid_value_contains_any_gid) end @@ -107,24 +138,10 @@ (custom_field_values_gids - actual_custom_field_values_gids).empty? end private - def pull_custom_field_or_raise(task, custom_field_gid) - custom_fields = task.custom_fields - if custom_fields.nil? - raise "Could not find custom_fields under task (was 'custom_fields' included in 'extra_fields'?)" - end - - matched_custom_field = custom_fields.find { |data| data.fetch('gid') == custom_field_gid } - if matched_custom_field.nil? - raise "Could not find custom field with gid #{custom_field_gid} in #{task.gid} with #{custom_fields}" - end - - matched_custom_field - end - def pull_enum_values(custom_field) resource_subtype = custom_field.fetch('resource_subtype') case resource_subtype when 'enum' [custom_field.fetch('enum_value')] @@ -162,9 +179,10 @@ FUNCTION_EVALUTORS = [ NotFunctionEvaluator, NilPFunctionEvaluator, TagPFunctionEvaluator, CustomFieldValueFunctionEvaluator, + CustomFieldGidValueFunctionEvaluator, CustomFieldGidValueContainsAnyGidFunctionEvaluator, AndFunctionEvaluator, ].freeze def evaluate(task_selector)