Class: Macaroni::Plugin::Filter::Deduped

Inherits:
Select
  • Object
show all
Defined in:
lib/macaroni/plugin/filter/deduped.rb

Instance Method Summary collapse

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(options={})
  @cache_path = options[: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