Class: Sup::Project

Inherits:
Object show all
Defined in:
lib/sup/differ/differ.rb

Overview

TODO: marshal dump these directly to yaml? or store in sqlite db

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, path) ⇒ Project

Returns a new instance of Project.



35
36
37
38
39
# File 'lib/sup/differ/differ.rb', line 35

def initialize(id, path)
  @id, @path = id, path
  @current_diff = ""
  @current_changed_files = {}
end

Instance Attribute Details

#current_diffObject

Returns the value of attribute current_diff.



34
35
36
# File 'lib/sup/differ/differ.rb', line 34

def current_diff
  @current_diff
end

Class Method Details

.allObject



78
79
80
81
82
# File 'lib/sup/differ/differ.rb', line 78

def all
  [].yamlize(GLOBAL_PROJECT_CONFIG_PATH).map do |project_config|
    new project_config['id'], project_config['path']
  end
end

Instance Method Details

#diff!Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/sup/differ/differ.rb', line 41

def diff!
  # figure out which specific files have changed since the last diff
  
  @changed_files = []
  @current_diffs = []
  
  Dir.chdir @path
  diff = `git diff`
  
  if diff != @current_diff
    @current_diff = diff
    
    # get array of changed files from git diff
    `git diff --stat`.scan(/^ (.*?)\s{1,}\|/m).flatten.each do |file|
      
      # get specific diff for file
      file_diff = `git diff #{file}`
      
      # if different from previous diff, store path and diff
      if @current_changed_files[file] != file_diff
        @current_changed_files[file] = file_diff
        @changed_files << file
        @current_diffs << file_diff
      end
    end
    
    supdate! unless @changed_files.empty?
  end
end

#supdate!Object



71
72
73
74
75
# File 'lib/sup/differ/differ.rb', line 71

def supdate!
  Sup::configure
  Sup::Api::Status.add :status_type => "StatusDiff", :message => @changed_files*', ',
    :text => @current_diffs*'\n'
end