Class: Feed2Gram::UpdatesCache

Inherits:
Object
  • Object
show all
Defined in:
lib/feed2gram/updates_cache.rb

Instance Method Summary collapse

Instance Method Details

#update!(cache, results, options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/feed2gram/updates_cache.rb', line 3

def update!(cache, results, options)
  cache.updated_at = Time.now
  results.group_by { |result| result.status }
    .transform_values { |results| results.map { |result| result.post.url } }
    .each do |status, urls|
    cache[status] += urls
  end

  puts "Writing updated cache to: #{options.cache_path}" if options.verbose
  File.write(options.cache_path, cache.as_yaml)
end