Class: SVNLogParser
- Inherits:
-
Object
- Object
- SVNLogParser
- Defined in:
- lib/codespicuous/svn_log_parser.rb
Instance Method Summary collapse
- #commits ⇒ Object
- #create_commit_changes_from_log_entry(logentry) ⇒ Object
- #create_commit_from_log_entry(logentry) ⇒ Object
- #extract_change_type(path) ⇒ Object
- #extract_kind(path) ⇒ Object
-
#initialize ⇒ SVNLogParser
constructor
A new instance of SVNLogParser.
- #parse(xml_to_parse = nil) ⇒ Object
- #validate_log_entry(logentry) ⇒ Object
- #validate_path(path) ⇒ Object
- #validate_xml(xml) ⇒ Object
- #xml_to_parse(xml_string) ⇒ Object
Constructor Details
#initialize ⇒ SVNLogParser
Returns a new instance of SVNLogParser.
8 9 10 |
# File 'lib/codespicuous/svn_log_parser.rb', line 8 def initialize @commits = Commits.new end |
Instance Method Details
#commits ⇒ Object
99 100 101 |
# File 'lib/codespicuous/svn_log_parser.rb', line 99 def commits @commits end |
#create_commit_changes_from_log_entry(logentry) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/codespicuous/svn_log_parser.rb', line 51 def create_commit_changes_from_log_entry(logentry) changes = [] logentry.elements.each("*/path") { |path| change = Change.new change.type = extract_change_type(path) change.kind = extract_kind(path) change.property_changed if path.attributes["prop-mods"] == "true" change.copyfrom = path.attributes["copyfrom-path"] change.copyrev = path.attributes["copyfrom-rev"] change.file = path.text changes << change } changes end |
#create_commit_from_log_entry(logentry) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/codespicuous/svn_log_parser.rb', line 29 def create_commit_from_log_entry(logentry) commit = Commit.new commit.revision = logentry.attributes["revision"] commit. = logentry.elements["author"].text commit. = logentry.elements["msg"].text commit.date = DateTime.parse(logentry.elements["date"].text) commit.changes = create_commit_changes_from_log_entry(logentry) commit end |
#extract_change_type(path) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/codespicuous/svn_log_parser.rb', line 39 def extract_change_type(path) return :modified if path.attributes["action"] == "M" return :added if path.attributes["action"] == "A" return :deleted if path.attributes["action"] == "D" return :renamed if path.attributes["action"] == "R" end |
#extract_kind(path) ⇒ Object
46 47 48 49 |
# File 'lib/codespicuous/svn_log_parser.rb', line 46 def extract_kind(path) return :file if path.attributes["kind"] == "file" return :dir if path.attributes["kind"] == "dir" end |
#parse(xml_to_parse = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/codespicuous/svn_log_parser.rb', line 16 def parse(xml_to_parse = nil) @xml_to_parse = xml_to_parse if xml_to_parse xml = REXML::Document.new(@xml_to_parse) validate_xml(xml) xml.elements.each( "*/logentry" ) do |logentry| commit = create_commit_from_log_entry(logentry) @commits.add(commit) end self end |
#validate_log_entry(logentry) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/codespicuous/svn_log_parser.rb', line 75 def validate_log_entry logentry invalid_attributes = logentry.attributes.collect { |a| a[0] unless a[0] == "revision" }.compact invalid_attributes.each { |a| raise ("Unexpected attributes log entry: " + a) } invalid_elements = logentry.elements.collect { |e| e.name unless ["author", "date", "paths", "msg"].include? e.name }.compact invalid_elements.each { |e| raise ("Unexpected element in log entry: " + e) } logentry.elements.each("*/path") { |path| validate_path path } end |
#validate_path(path) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/codespicuous/svn_log_parser.rb', line 87 def validate_path path path.elements.each { |e| raise ("Unexpected element in path: " + e.name) } invalid_attributes = path.attributes.collect { |a| a[0] unless ["action", "prop-mods", "text-mods", "kind", "copyfrom-path", "copyfrom-rev"].include? a[0] }.compact invalid_attributes.each { |a| raise ("Unexpected attributes in path: " + a) } raise("Unexpected value to attribute action in path: " + path.attributes["action"]) unless ["R", "M", "A", "D"].include?(path.attributes["action"]) raise("Unexpected value to attribute kind in path: " + path.attributes["kind"]) unless ["file", "dir"].include?(path.attributes["kind"]) puts "Unexpected value to attribute text-mods in path: " + path.attributes["text-mods"] if path.attributes["text-mods"] == "false" and not ["D", "R"].include?(path.attributes["action"]) and path.attributes["kind"] != "dir" end |
#validate_xml(xml) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/codespicuous/svn_log_parser.rb', line 66 def validate_xml(xml) non_logentries = xml.elements["log"].elements.collect { |e| e.name unless e.name == "logentry" }.compact non_logentries.each { |e| raise("Unexpected log entry: " + e) } xml.elements.each( "*/logentry" ) do |logentry| validate_log_entry(logentry) end end |
#xml_to_parse(xml_string) ⇒ Object
12 13 14 |
# File 'lib/codespicuous/svn_log_parser.rb', line 12 def xml_to_parse(xml_string) @xml_to_parse = xml_string end |