Class: Cache
- Inherits:
-
Object
- Object
- Cache
- Defined in:
- lib/githabit/cache.rb
Overview
Cachefile will be eventype:id PushEvent:SHAHASH IssueEvent:ISSUEID
Instance Method Summary collapse
- #cache(event) ⇒ Object
- #cached?(cache_id) ⇒ Boolean
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
7 8 9 10 11 12 13 14 15 |
# File 'lib/githabit/cache.rb', line 7 def initialize() @cache = [] @file_cache = open(File.("~/.githabit.cache"), "a+") # Load cache @file_cache.each do |line| @cache.push(line.strip) end end |
Instance Method Details
#cache(event) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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) ⇒ Boolean
17 18 19 |
# File 'lib/githabit/cache.rb', line 17 def cached? (cache_id) @cache.include? cache_id end |