Sha256: b4b98b8c8b1f9a1e70ef66822d47b5490dfa4a4b65e21163f3e2f8b1d2e3e4d7

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require "rubycritic/smells_serializer"
require "rubycritic/source_locator"
require "rubycritic/analysers_runner"
require "rubycritic/smells_aggregator"
require "rubycritic/smells_status_setter"

module Rubycritic

  class RevisionComparator
    SNAPSHOTS_DIR_NAME = "snapshots"

    def initialize(smells, source_control_system)
      @smells_now = smells
      @source_control_system = source_control_system
    end

    def smells
      SmellsStatusSetter.new(smells_before, @smells_now).smells
    end

    private

    def smells_before
      serializer = SmellsSerializer.new(revision_file)
      if File.file?(revision_file)
        serializer.load
      else
        smells = nil
        @source_control_system.travel_to_head do
          smell_adapters = AnalysersRunner.new(paths_of_tracked_files).run
          smells = SmellsAggregator.new(smell_adapters).smells
        end
        serializer.dump(smells)
        smells
      end
    end

    def revision_file
      @revision_file ||= File.join(
        ::Rubycritic.configuration.root,
        SNAPSHOTS_DIR_NAME,
        @source_control_system.head_reference
      )
    end

    def paths_of_tracked_files
      SourceLocator.new(["."]).paths
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubycritic-0.0.10 lib/rubycritic/revision_comparator.rb
rubycritic-0.0.9 lib/rubycritic/revision_comparator.rb