Class: Macaroni::Plugin::Filter::Deduped
- Inherits:
-
Select
- Object
- Select
- Macaroni::Plugin::Filter::Deduped
- Defined in:
- lib/macaroni/plugin/filter/deduped.rb
Instance Method Summary collapse
- #exec(data) ⇒ Object
-
#initialize(options = {}) ⇒ Deduped
constructor
A new instance of Deduped.
Constructor Details
#initialize(options = {}) ⇒ Deduped
Returns a new instance of Deduped.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/macaroni/plugin/filter/deduped.rb', line 8 def initialize(={}) @cache_path = [:cache_path] || '/tmp/macaroni-cache' @block = lambda { |entry| hash = Digest::MD5.hexdigest(entry.url) hash_path = File.join(@cache_path, hash) deduped = !File.exists?(hash_path) File.open(hash_path, 'w') do |file| file.write({ :url => entry.url, :title => entry.title, :content => entry.content, }.to_yaml) end if deduped deduped } end |
Instance Method Details
#exec(data) ⇒ Object
27 28 29 30 |
# File 'lib/macaroni/plugin/filter/deduped.rb', line 27 def exec(data) FileUtils.mkdir_p(@cache_path) if !File.exists?(@cache_path) super end |