Sha256: f547b244162e6198b14d3d19e7e8b7337147d480e670c4e9c7e44bfc92d2c665

Contents?: true

Size: 1.1 KB

Versions: 17

Compression:

Stored size: 1.1 KB

Contents

module Churn

  # responcible 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 'tmp' unless File.directory?('tmp')
      File.open("tmp/#{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/#{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

  end

end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
churn-0.0.29 lib/churn/churn_history.rb
churn-0.0.28 lib/churn/churn_history.rb
churn-0.0.27 lib/churn/churn_history.rb
churn-0.0.26 lib/churn/churn_history.rb
churn-0.0.25 lib/churn/churn_history.rb
churn-0.0.24 lib/churn/churn_history.rb
churn-0.0.23 lib/churn/churn_history.rb
churn-0.0.22 lib/churn/churn_history.rb
churn-0.0.21 lib/churn/churn_history.rb
churn-0.0.20 lib/churn/churn_history.rb
churn-0.0.19 lib/churn/churn_history.rb
rferraz-churn-0.0.19 lib/churn/churn_history.rb
rferraz-churn-0.0.17 lib/churn/churn_history.rb
rferraz-churn-0.0.16 lib/churn/churn_history.rb
churn-0.0.15 lib/churn/churn_history.rb
churn-0.0.14 lib/churn/churn_history.rb
churn-0.0.13 lib/churn/churn_history.rb