class Cache

Cachefile will be eventype:id PushEvent:SHAHASH IssueEvent:ISSUEID

Public Class Methods

new() click to toggle source
# File lib/githabit/cache.rb, line 7
def initialize()
  @cache = []
  @file_cache = open(File.expand_path("~/.githabit.cache"), "a+")

  # Load cache
  @file_cache.each do |line|
    @cache.push(line.strip)
  end
end

Public Instance Methods

cache(event) click to toggle source
# File lib/githabit/cache.rb, line 21
def cache (event)
  if (event['type'] == 'PushEvent')
    # Cache each of the commits
    event['payload']['commits'].each do |commit|
      if (!cached? "Commit:#{commit['sha']}")
        add("Commit:#{commit['sha']}")
      end
    end
  elsif (event['type'] == "IssuesEvent")
    if (!cached? "Issue:#{event['id']}")
      add("Issue:#{event['id']}")
    end
  end
end
cached?(cache_id) click to toggle source
# File lib/githabit/cache.rb, line 17
def cached? (cache_id)
  @cache.include? cache_id
end

Private Instance Methods

add(cache_id) click to toggle source
# File lib/githabit/cache.rb, line 38
def add (cache_id)
  @cache.push(cache_id)

  # Write cache to file
  @file_cache.write(cache_id)
  @file_cache.write("\n")
end