class TFSGraph::Branch

Constants

ARCHIVED_FLAGS
BRANCH_TYPES
RELEASE_MATCHER
SCHEMA

Public Class Methods

new(repo, args) click to toggle source
Calls superclass method
# File lib/tfs_graph/branch.rb, line 32
def initialize(repo, args)
  super

  detect_type
  detect_archived
end

Private Class Methods

repath_archive(path) click to toggle source
# File lib/tfs_graph/branch.rb, line 196
def self.repath_archive(path)
  path = path.dup
  return path unless ARCHIVED_FLAGS.any? {|flag| path.include? flag }

  ARCHIVED_FLAGS.each {|flag| path.gsub!(/#{flag}>?(?:.*)>/, "") }
  path
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/tfs_graph/branch.rb, line 166
def <=>(other)
  path <=> other.path
end
absolute_root() click to toggle source

returns a branch

# File lib/tfs_graph/branch.rb, line 93
def absolute_root
  @absolute_root ||= @repo.absolute_root_for(self)
end
active?() click to toggle source
# File lib/tfs_graph/branch.rb, line 61
def active?
  !hidden? && !archived?
end
add_changeset(changeset) click to toggle source
# File lib/tfs_graph/branch.rb, line 110
def add_changeset(changeset)
  # attach branch path
  changeset.branch_path = self.path
  changeset.save!

  @repo.relate(:changesets, self.db_object, changeset.db_object)
end
add_child(changeset) click to toggle source
# File lib/tfs_graph/branch.rb, line 118
def add_child(changeset)
  @repo.relate(:child, self.db_object, changeset.db_object)
end
ahead_of_master() click to toggle source
# File lib/tfs_graph/branch.rb, line 138
def ahead_of_master
  return 0 unless absolute_root
  my_changes = changesets
  root_changes = absolute_root.merged_changesets

  # get intersection between root and this branch
  intersect = root_changes & my_changes
  # get difference of intersect with my changes
  diff = my_changes - intersect

  diff.count
end
archive!() click to toggle source
# File lib/tfs_graph/branch.rb, line 83
def archive!
  self.archived = true
  save!
end
archived() click to toggle source
# File lib/tfs_graph/branch.rb, line 45
def archived
  @archived.to_s
end
archived?() click to toggle source
# File lib/tfs_graph/branch.rb, line 53
def archived?
  archived.to_s == "true"
end
as_json(options={}) click to toggle source
Calls superclass method
# File lib/tfs_graph/branch.rb, line 170
def as_json(options={})
  results = super
  results[:related_branches] = related_branches
  results[:id] = id

  results
end
behind_master() click to toggle source

gets the set of changesets that exist in both root and self then gets a diff of that set and the root.

# File lib/tfs_graph/branch.rb, line 153
def behind_master
  return 0 unless absolute_root
  my_changes = merged_changesets
  root_changes = absolute_root.changesets

  # get intersect between my changes and the root
  intersect = my_changes & root_changes
  # get diff of root changes to intersect
  diff = root_changes - intersect

  diff.count
end
branch?() click to toggle source
# File lib/tfs_graph/branch.rb, line 97
def branch?
  !master?
end
changesets() click to toggle source
# File lib/tfs_graph/branch.rb, line 122
def changesets
  @repo.get_nodes(db_object, :outgoing, :changesets, Changeset)
end
contributors() click to toggle source
# File lib/tfs_graph/branch.rb, line 126
def contributors
  changesets.group_by(&:committer)
end
hidden() click to toggle source
# File lib/tfs_graph/branch.rb, line 49
def hidden
  @hidden.to_s
end
hidden?() click to toggle source
# File lib/tfs_graph/branch.rb, line 57
def hidden?
  hidden.to_s == "true"
end
hide!() click to toggle source
# File lib/tfs_graph/branch.rb, line 78
def hide!
  self.hidden = true
  save!
end
last_changeset() click to toggle source
# File lib/tfs_graph/branch.rb, line 134
def last_changeset
  changesets.last
end
merged_changesets() click to toggle source
# File lib/tfs_graph/branch.rb, line 106
def merged_changesets
  @repo.get_nodes(db_object, :outgoing, :included, Changeset)
end
named_type() click to toggle source
# File lib/tfs_graph/branch.rb, line 65
def named_type
  BRANCH_TYPES[type]
end
root_changeset() click to toggle source
# File lib/tfs_graph/branch.rb, line 130
def root_changeset
  @root = @repo.get_nodes(db_object, :outgoing, :child, Changeset).first if (@root.nil? || @root.empty?)
end
rootless?() click to toggle source
# File lib/tfs_graph/branch.rb, line 88
def rootless?
  !master? && root.empty?
end
type_index(name) click to toggle source
# File lib/tfs_graph/branch.rb, line 178
def type_index(name)
  BRANCH_TYPES.index(name.to_sym)
end
updated!() click to toggle source
# File lib/tfs_graph/branch.rb, line 69
def updated!
  @last_updated = Time.now.utc
  save!
end
updated_since?(date) click to toggle source
# File lib/tfs_graph/branch.rb, line 74
def updated_since?(date)
  @last_updated > date
end

Private Instance Methods

detect_archived() click to toggle source
# File lib/tfs_graph/branch.rb, line 191
def detect_archived
  self.archived = ARCHIVED_FLAGS.any? {|flag| original_path && original_path.include?(flag) }
  nil
end
detect_type() click to toggle source
# File lib/tfs_graph/branch.rb, line 184
def detect_type
  return self.type = type_index(:master) if (root.nil? || root.empty?)
  return self.type = type_index(:release) if !(name =~ RELEASE_MATCHER).nil?
  self.type = type_index(:feature)
  nil
end