Class Yapra::Plugin::Filter::Deduped
In: lib-plugins/yapra/plugin/filter/deduped.rb
Parent: Yapra::Plugin::Base

Filter::Deduped - Plugin to get Deduped entries — original by emergent

Plugin to get Deduped entries Cache path can be set.

Methods

on_error   run  

Public Instance methods

[Source]

    # File lib-plugins/yapra/plugin/filter/deduped.rb, line 52
52:     def on_error(ex)
53:       logger.debug('error is occured.')
54:       FileUtils.rm(@cache_paths, {:force => true})
55:     end

[Source]

    # File lib-plugins/yapra/plugin/filter/deduped.rb, line 17
17:     def run(data)
18:       cacheroot = Pathname.new(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'cache'))
19:       cachepath = Pathname.new(config['path']) || cacheroot
20:       if cachepath.relative?
21:         cachepath = cacheroot + cachepath
22:       end
23:       
24:       unless File.exists?(cachepath)
25:         FileUtils.mkdir_p(cachepath)
26:       end
27:       
28:       attribute = config['attribute']
29:       
30:       @cache_paths = []
31:       deduped_data = data.select {|d|
32:         v = d.link rescue d.to_s
33:         if attribute && d.respond_to?(attribute)
34:           v = d.__send__(attribute).to_s
35:         end
36:         hashpath = File.join(cachepath.to_s, Digest::MD5.hexdigest(v))
37:         if File.exists?(hashpath)
38:           false
39:         else
40:           begin
41:             File.open(hashpath, "wb").write(v)
42:             @cache_paths << hashpath
43:             true
44:           rescue 
45:             false
46:           end
47:         end
48:       }
49:       return deduped_data
50:     end

[Validate]