def run(data)
cacheroot = Pathname.new(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'cache'))
cachepath = Pathname.new(config['path']) || cacheroot
if cachepath.relative?
cachepath = cacheroot + cachepath
end
unless File.exists?(cachepath)
FileUtils.mkdir_p(cachepath)
end
attribute = config['attribute']
@cache_paths = []
deduped_data = data.select {|d|
v = d.link rescue d.to_s
if attribute && d.respond_to?(attribute)
v = d.__send__(attribute).to_s
end
hashpath = File.join(cachepath.to_s, Digest::MD5.hexdigest(v))
if File.exists?(hashpath)
false
else
begin
File.open(hashpath, "wb").write(v)
@cache_paths << hashpath
true
rescue
false
end
end
}
return deduped_data
end