Sha256: 6f4f34982b2c24a31f37782d777d9b5538f3667b49e38602b68a4fb59c4a1fce
Contents?: true
Size: 1.57 KB
Versions: 23
Compression:
Stored size: 1.57 KB
Contents
require_relative 'diff_sortable/for_unarchive' require_relative 'diff_sortable/for_archive' class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs module Stages module DiffSortable class << self def included(base) super base.send(:include, Sortable) end end include ForUnarchive include ForArchive private # @yield # @yieldreturn [Array<Diff>] the raw diffs of `stage` def sort_diffs(stage) raise ArgumentError, "Expecting block but not given" unless block_given? raw_diffs = yield case stage when :archive only_first_ancestor_in_chains(sort_top_to_bottom(raw_diffs, stage)) when :unarchive raw_diffs = include_unarchive_of_archived_ancestors(raw_diffs) sort_top_to_bottom(uniq_archive_token(raw_diffs, stage), stage) when :move sort_bottom_to_top(raw_diffs, stage) else sort_top_to_bottom(raw_diffs, stage) end end # It should also include archived ancestors !! # @note this will translate to the unarchive of a wider range of nodes. # - Please notice that the design is correct (there's no way around it) def uniq_archive_token(raw_diffs, stage) raw_diffs.group_by(&:archived_token_prev).each_with_object([]) do |(token, token_diffs), out| next out.concat(token_diffs) unless token out << sort_top_to_bottom(token_diffs, stage).first end end end end end
Version data entries
23 entries across 23 versions & 1 rubygems