Sha256: af295f186d5b87ada6885af90f5cabafbffaab24a6268a1e3c691ba10f6b7026

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

module Churn

  # responsible for storing the churn history to json,
  # and for loading old churn history data from json.
  class ChurnHistory

    #takes current revision and it's hash_data and stores it
    def self.store_revision_history(revision, hash_data)
      FileUtils.mkdir_p tmp_churn_directory unless File.directory?(tmp_churn_directory)
      File.open("#{tmp_churn_directory}/#{revision}.json", 'w') {|file| file.write(hash_data.to_json) }
    end
    
    #given a previous project revision find and load the churn data from a json file
    def self.load_revision_data(revision)
      #load revision data from scratch folder if it exists
      filename = "#{tmp_churn_directory}/#{revision}.json"
      if File.exists?(filename)
        begin
          json_data = File.read(filename)
          data      = JSON.parse(json_data)
          changed_files   = data['churn']['changed_files']
          changed_classes = data['churn']['changed_classes']
          changed_methods = data['churn']['changed_methods']
        rescue JSON::ParserError
          #leave all of the objects nil
        end
      end
      [changed_files, changed_classes, changed_methods]
    end

    def self.tmp_churn_directory
      ChurnOptions.instance.data_directory
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
churn-0.0.35 lib/churn/history.rb
churn-0.0.34 lib/churn/churn_history.rb
churn-0.0.33 lib/churn/churn_history.rb
churn-0.0.32 lib/churn/churn_history.rb
churn-0.0.31 lib/churn/churn_history.rb
churn-0.0.30 lib/churn/churn_history.rb