Sha256: bccdf52e1b685e82741a1508767d4059d5b51301d43dc921c09b95f7d53366e2

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

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

module Rubycritic

  class RevisionComparator
    SNAPSHOTS_DIR = File.expand_path("tmp/rubycritic/snapshots", Dir.getwd)

    def initialize(paths, source_control_system)
      @paths = paths
      @source_control_system = source_control_system
    end

    def compare
      SmellsStatusSetter.new(smelly_pathnames_before, smelly_pathnames_now).smelly_pathnames
    end

    private

    def smelly_pathnames_before
      serializer = SmellyPathnamesSerializer.new(revision_file)
      if File.file?(revision_file)
        serializer.load
      else
        smelly_pathnames = nil
        @source_control_system.travel_to_head do
          smelly_pathnames = smelly_pathnames(paths_of_tracked_files)
        end
        serializer.dump(smelly_pathnames)
        smelly_pathnames
      end
    end

    def smelly_pathnames_now
      smelly_pathnames(@paths)
    end

    def smelly_pathnames(paths)
      smell_adapters = AnalysersRunner.new(paths).run
      SmellsAggregator.new(smell_adapters).smelly_pathnames
    end

    def revision_file
      @revision_file ||= File.join(SNAPSHOTS_DIR, @source_control_system.head_reference)
    end

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

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubycritic-0.0.7 lib/rubycritic/revision_comparator.rb
rubycritic-0.0.6 lib/rubycritic/revision_comparator.rb
rubycritic-0.0.5 lib/rubycritic/revision_comparator.rb
rubycritic-0.0.4 lib/rubycritic/revision_comparator.rb
rubycritic-0.0.3 lib/rubycritic/revision_comparator.rb
rubycritic-0.0.2 lib/rubycritic/revision_comparator.rb