Class: Churn::ChurnHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/churn/churn_history.rb

Overview

responcible for storing the churn history to json, and for loading old churn history data from json.

Class Method Summary collapse

Class Method Details

.load_revision_data(revision) ⇒ Object

given a previous project revision find and load the churn data from a json file



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/churn/churn_history.rb', line 14

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

.store_revision_history(revision, hash_data) ⇒ Object

takes current revision and it’s hash_data and stores it



8
9
10
11
# File 'lib/churn/churn_history.rb', line 8

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