Class: Change
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Change
- Defined in:
- app/models/change.rb
Overview
Motiro - A project tracking tool
Copyright (C) 2006-2008 Thiago Arrais
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation; either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Instance Method Summary collapse
- #chunked_diff ⇒ Object
- #filled? ⇒ Boolean
- #has_diff? ⇒ Boolean
- #qualified_resource_name ⇒ Object
- #resource_name ⇒ Object
- #to_s ⇒ Object
- #use_differ(differ) ⇒ Object
Instance Method Details
#chunked_diff ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/change.rb', line 19 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
54 55 56 |
# File 'app/models/change.rb', line 54 def filled? self.resource_kind && ('dir' == self.resource_kind || has_diff?) end |
#has_diff? ⇒ Boolean
58 59 60 |
# File 'app/models/change.rb', line 58 def has_diff? return ! (diff.nil? or diff.empty?) end |
#qualified_resource_name ⇒ Object
46 47 48 |
# File 'app/models/change.rb', line 46 def qualified_resource_name return summary.match(/(\w )?([^\s]+)/)[2] end |
#resource_name ⇒ Object
50 51 52 |
# File 'app/models/change.rb', line 50 def resource_name return qualified_resource_name.split('/').last end |
#to_s ⇒ Object
42 43 44 |
# File 'app/models/change.rb', line 42 def to_s return summary end |
#use_differ(differ) ⇒ Object
62 63 64 |
# File 'app/models/change.rb', line 62 def use_differ(differ) @differ = differ end |