Class: Hubeye::Server::Tracker

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hubeye/server/tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTracker

Returns a new instance of Tracker.



13
14
15
# File 'lib/hubeye/server/tracker.rb', line 13

def initialize
  @commit_list = []
end

Instance Attribute Details

#commit_listObject (readonly)

Returns the value of attribute commit_list.



11
12
13
# File 'lib/hubeye/server/tracker.rb', line 11

def commit_list
  @commit_list
end

Instance Method Details

#add(repo_name) ⇒ Object Also known as: <<

returns one of:

:added
:replaced
:unchanged
:invalid

A commit won’t be added if the repo is already tracked and the newly searched for commit sha is the same as the old one. Every call to #add requires a trip to a Github server. NOTE: takes full repo_name only



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hubeye/server/tracker.rb', line 28

def add(repo_name)
  raw_commit_ary = recent_repo_info(repo_name)
  return :invalid unless raw_commit_ary
  commit = Commit.new(repo_name, raw_commit_ary)
  if tracking?(repo_name) && unchanged?(commit)
    return :unchanged
  end
  state = tracking?(repo_name) ? :replaced : :added
  # update the list
  @commit_list.reject! {|cmt| cmt.repo_name == repo_name} if state == :replaced
  @commit_list << commit
  state
end

#commit(repo_name) ⇒ Object Also known as: tracking?

returns the most recently tracked commit object for that full repo name, or nil if it isn’t tracked.



54
55
56
57
# File 'lib/hubeye/server/tracker.rb', line 54

def commit(repo_name)
  @commit_list.each {|cmt| return cmt if cmt.repo_name == repo_name}
  nil
end

#delete(repo_name) ⇒ Object

returns true if deleted, false otherwise.



45
46
47
48
49
50
# File 'lib/hubeye/server/tracker.rb', line 45

def delete(repo_name)
  old_length = @commit_list.length
  @commit_list.delete_if {|cmt| cmt.repo_name == repo_name}
  new_length = @commit_list.length
  old_length != new_length
end

#repo_namesObject

returns a list of repo names being tracked



61
62
63
# File 'lib/hubeye/server/tracker.rb', line 61

def repo_names
  @commit_list.map {|cmt| cmt.repo_name }
end