def run(task, options = {})
      from = options[:triggered_by] || options[:upstream] || task
      to = options[:triggers] || options[:downstream] || task

      tasks = @tasks.map(&:name)
      direction = options[:upstream] || options[:triggered_by] ? 'upstream' : 'downstream'

      # Throw an error if either up- or downstream task doesn't exist
      non_existing_tasks = ([from, to] - tasks).uniq
      raise "Couldn't set #{direction} dependency for non-existing task #{non_existing_tasks.first}" if non_existing_tasks.any?

      # Throw an error if unsupported dependencies are set
      raise "Multiple upstream tasks aren't supported" if from.is_a?(Array)
      raise "Multiple downstream tasks aren't supported" if to.is_a?(Array)

      # Set explicit root task and skip further processing if the Chore has
      # just one task defined or if only one of its tasks is set to run
      if tasks.one? || from == to
        @dag.root!(@dag.find_by(name: from))
        return
      end

      v1 = @dag.vertices.detect { |vertex| vertex[:name] == from }
      v2 = @dag.vertices.detect { |vertex| vertex[:name] == to }

      @dag.add_edge(from: v1, to: v2)
    end
def run(task, options = {})
      from = options[:triggered_by] || options[:upstream] || task
      to = options[:triggers] || options[:downstream] || task

      tasks = @tasks.map(&:name)
      direction = options[:upstream] || options[:triggered_by] ? 'upstream' : 'downstream'

      # Throw an error if either up- or downstream task doesn't exist
      non_existing_tasks = ([from, to] - tasks).uniq
      raise "Couldn't set #{direction} dependency for non-existing task #{non_existing_tasks.first}" if non_existing_tasks.any?

      # Throw an error if unsupported dependencies are set
      raise "Multiple upstream tasks aren't supported" if from.is_a?(Array)
      raise "Multiple downstream tasks aren't supported" if to.is_a?(Array)

      # Set explicit root task and skip further processing if the Chore has
      # just one task defined or if only one of its tasks is set to run
      if tasks.one? || from == to
        @dag.root!(@dag.find_by(name: from))
        return
      end

      v1 = @dag.vertices.detect { |vertex| vertex[:name] == from }
      v2 = @dag.vertices.detect { |vertex| vertex[:name] == to }

      @dag.add_edge(from: v1, to: v2)
    end
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity