class OhlohScm::BazaarListener
Attributes
Public Class Methods
Source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 13 def initialize(callback) @callback = callback @merge_commit = [] @state = :none @authors = [] end
Public Instance Methods
Source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 80 def cdata(data) @cdata = data end
rubocop:disable Style/TrivialAccessors # Cannot use attr_writer; we need cdata not cdata=.
Source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 44 def tag_end(name) case name when 'log' @callback.call(@commit) when 'revisionid' @commit.token = @text when 'message' @commit.message = @cdata when 'committer' committer = BzrXmlParser.capture_name(@text) @commit.committer_name = committer[0] @commit.committer_email = committer[1] when 'author' author = BzrXmlParser.capture_name(@text) @authors << { author_name: author[0], author_email: author[1] } when 'timestamp' @commit.committer_date = Time.parse(@text) when 'file' @diffs.concat(parse_diff(@action, @text, @before_path)) if @state == :collect_files @before_path = nil @text = nil when 'added', 'modified', 'removed', 'renamed' @state = :none when 'affected-files' @commit.diffs = remove_dupes(@diffs) when 'merge' @commit = @merge_commit.pop when 'authors' @commit.author_name = @authors[0][:author_name] @commit.author_email = @authors[0][:author_email] @authors.clear end end
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
Source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 21 def tag_start(name, attrs) case name when 'log' @commit = OhlohScm::Commit.new @commit.diffs = [] when 'affected-files' @diffs = [] when 'added', 'modified', 'removed', 'renamed' @action = name @state = :collect_files when 'file' @before_path = attrs['oldpath'] when 'merge' # This is a merge commit, save it and pop it after all branch commits @merge_commit.push(@commit) when 'authors' @state = :collect_authors @authors = [] end end
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
Source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 84 def text(text) @text = text end
Private Instance Methods
Source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 93 def parse_diff(action, path, before_path) diffs = [] case action # A rename action requires two diffs: one to remove the old filename, # another to add the new filename. # # Note that is possible to be renamed to the empty string! # This happens when a subdirectory is moved to become the root. when 'renamed' diffs = [OhlohScm::Diff.new(action: 'D', path: before_path), OhlohScm::Diff.new(action: 'A', path: path || '')] when 'added' diffs = [OhlohScm::Diff.new(action: 'A', path: path)] when 'modified' diffs = [OhlohScm::Diff.new(action: 'M', path: path)] when 'removed' diffs = [OhlohScm::Diff.new(action: 'D', path: path)] end diffs.each do |d| d.path = strip_trailing_asterisk(d.path) end diffs end
rubocop:disable Metrics/MethodLength Parse one single diff
Source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 122 def remove_dupes(diffs) BzrXmlParser.remove_dupes(diffs) end
Source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 118 def strip_trailing_asterisk(path) path[-1..-1] == '*' ? path[0..-2] : path end
rubocop:enable Metrics/MethodLength