lib/s3repo/repo.rb in s3repo-0.0.2 vs lib/s3repo/repo.rb in s3repo-0.0.3
- old
+ new
@@ -1,44 +1,52 @@
+require 'basiccache'
+
module S3Repo
##
# Repo object, represents an Arch repo inside an S3 bucket
class Repo < Base
+ def initialize(params = {})
+ super
+ end
+
def add_package(file)
upload!(file)
- package = Package.new(client: client, key: file)
- metadata.add_package(package)
- package
end
def packages
- @packages ||= parse_packages
+ meta_cache.cache { parse_packages }
end
- def serve(path, recheck = true)
- cache.serve(path, recheck)
+ def include?(key)
+ !packages.find { |x| x.key == key }.nil?
end
- def metadata
- @metadata ||= Metadata.new(client: client)
+ def serve(key)
+ refresh = !key.match(/\.pkg\.tar\.xz$/)
+ file_cache.serve(key, refresh)
end
private
- def cache
- @cache ||= Cache.new(client: client, tmpdir: @options[:tmpdir])
+ def file_cache
+ @file_cache ||= Cache.new(client: client, tmpdir: @options[:tmpdir])
end
+ def meta_cache
+ @meta_cache ||= BasicCache::TimeCache.new lifetime: 600
+ end
+
def upload!(file)
client.put_object(
bucket: bucket,
key: file,
body: File.open(file) { |fh| fh.read }
)
end
def parse_packages
- resp = client.list_objects(bucket: bucket).contents.map(&:key)
- resp.select! { |x| x.match(/.*\.pkg\.tar\.xz$/) }
- resp.map { |x| Package.new(client: client, key: x) }
+ client.list_objects(bucket: bucket).contents.select do |x|
+ x.key.match(/.*\.pkg\.tar\.xz$/)
+ end
end
end
end