Sha256: 771b1528fb9a93288a324464a06662eb3dc1a0b3972756424b8a3f2fb8f483c3

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'rubycritic/serializer'
require 'rubycritic/analysers_runner'
require 'rubycritic/smells_status_setter'
require 'rubycritic/version'
require 'digest/md5'

module Rubycritic
  class RevisionComparator
    SNAPSHOTS_DIR_NAME = 'snapshots'.freeze

    def initialize(paths)
      @paths = paths
    end

    def set_statuses(analysed_modules_now)
      if Config.source_control_system.revision?
        SmellsStatusSetter.set(
          analysed_modules_before.flat_map(&:smells),
          analysed_modules_now.flat_map(&:smells)
        )
      end
      analysed_modules_now
    end

    private

    def analysed_modules_before
      serializer = Serializer.new(revision_file)
      if File.file?(revision_file)
        serializer.load
      else
        analysed_modules = nil
        Config.source_control_system.travel_to_head do
          analysed_modules = AnalysersRunner.new(@paths).run
        end
        serializer.dump(analysed_modules)
        analysed_modules
      end
    end

    def revision_file
      @revision_file ||= File.join(
        Config.root,
        SNAPSHOTS_DIR_NAME,
        VERSION,
        Digest::MD5.hexdigest(Marshal.dump(@paths)),
        Config.source_control_system.head_reference
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubycritic-2.7.0 lib/rubycritic/revision_comparator.rb