Class: Change

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/change.rb

Overview

Motiro - A project tracking tool

Copyright (C) 2006-2007  Thiago Arrais

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Instance Method Summary collapse

Instance Method Details

#chunked_diffObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/change.rb', line 20

def chunked_diff
  return nil unless has_diff?
  return @chunked_diff if @chunked_diff
  @differ ||= DiffChunkBuilder.new
  diff.split("\n").each do |line|
    c = line[0,1]
    line_text = line[1, line.length - 1]
    
    if '+' == c then
      @differ.push_addition line_text
    elsif '-' == c then
      @differ.push_deletion line_text
    elsif ' ' == c then
      @differ.push_unchanged line_text
    elsif '@' == c then
      md = line_text.match(/-(\d+)[^\+]*\+(\d+)/)
      @differ.start_line(md[1].to_i, md[2].to_i)
    end
  end
  
  @chunked_diff = @differ.get_chunks
end

#filled?Boolean



55
56
57
# File 'app/models/change.rb', line 55

def filled?
  self.resource_kind && ('dir' == self.resource_kind || has_diff?)
end

#has_diff?Boolean



59
60
61
# File 'app/models/change.rb', line 59

def has_diff?
  return ! (diff.nil? or diff.empty?)
end

#qualified_resource_nameObject



47
48
49
# File 'app/models/change.rb', line 47

def qualified_resource_name
  return summary.match(/(\w )?([^\s]+)/)[2]
end

#resource_nameObject



51
52
53
# File 'app/models/change.rb', line 51

def resource_name
  return qualified_resource_name.split('/').last
end

#to_sObject



43
44
45
# File 'app/models/change.rb', line 43

def to_s
  return summary
end

#use_differ(differ) ⇒ Object



63
64
65
# File 'app/models/change.rb', line 63

def use_differ(differ)
  @differ = differ
end