Sha256: 5c187cc6b9e1f7b10793000c2aae5c04d351bd04023215eb989083d009da140a

Contents?: true

Size: 658 Bytes

Versions: 10

Compression:

Stored size: 658 Bytes

Contents

module Feed2Gram
  Cache = Struct.new(:updated_at, :posted, :failed, :skipped, keyword_init: true) do
    def as_yaml
      to_h.transform_keys(&:to_s).to_yaml.gsub(/^---\n/, "")
    end
  end

  class LoadsCache
    def load(options)
      if File.exist?(options.cache_path)
        puts "Loading cache from: #{options.cache_path}" if options.verbose
        yaml = YAML.load_file(options.cache_path, permitted_classes: [Time])
        Cache.new(**yaml)
      else
        puts "No cache found (looked at '#{options.cache_path}'), initializing a new one" if options.verbose
        Cache.new(posted: [], failed: [], skipped: [])
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
feed2gram-1.4.0 lib/feed2gram/loads_cache.rb
feed2gram-1.3.0 lib/feed2gram/loads_cache.rb
feed2gram-1.2.4 lib/feed2gram/loads_cache.rb
feed2gram-1.2.2 lib/feed2gram/loads_cache.rb
feed2gram-1.2.1 lib/feed2gram/loads_cache.rb
feed2gram-1.2.0 lib/feed2gram/loads_cache.rb
feed2gram-1.1.0 lib/feed2gram/loads_cache.rb
feed2gram-1.0.0 lib/feed2gram/loads_cache.rb
feed2gram-0.0.4 lib/feed2gram/loads_cache.rb
feed2gram-0.0.3 lib/feed2gram/loads_cache.rb