Sha256: 893201a9d32d1e241e8e6472934854fedb2661987f3964cde93def4960cc5c73
Contents?: true
Size: 1.58 KB
Versions: 20
Compression:
Stored size: 1.58 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
20 entries across 20 versions & 1 rubygems