Sha256: 0d0eff731ccec5d1ddb4a039c678dfaf633aa59f935ed6342bfda2cad37d873c

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

## Filter::deduped - Plugin to get Deduped entries -- emergent
## 
## Plugin to get Deduped entries
## Cache path can be set.
##
## - module: Filter::deduped
##   config:
##    path: /tmp/cache/hoge
##
require 'pathname'
require 'digest/md5'

def mkdir_p path
  begin
    Dir.mkdir(path)
  rescue Errno::ENOENT
    mkdir_p Pathname.new(path).parent
    retry
  rescue Errno::EACCES
    raise
  end
  0
end

def deduped config, data
  cacheroot = Pathname(__FILE__).parent.parent.parent.realpath + 'cache'
  cachepath = Pathname.new(config['path']) || root
  if cachepath.relative?
    cachepath = cacheroot + cachepath
  end
  puts '  cache path: ' + cachepath

  if !File.exists?(cachepath)
    begin
      mkdir_p cachepath
    rescue
      puts "could'nt make cache directory"
      return data
    end
  end
  
  deduped_data = data.select {|d|
    hashpath = cachepath.to_s + '/' + Digest::MD5.hexdigest(d.to_s)
    if File.exists?(hashpath)
      false
    else 
      File.open(hashpath, "wb").write(d.to_s) rescue false
    end
  }
  return deduped_data
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
yapra-0.2.2 legacy_plugins/Filter/deduped.rb
yapra-0.2.0 legacy_plugins/Filter/deduped.rb
yapra-0.1.3 legacy_plugins/Filter/deduped.rb
yapra-0.1.0 legacy_plugins/Filter/deduped.rb
yapra-0.1.1 legacy_plugins/Filter/deduped.rb
yapra-0.1.2 legacy_plugins/Filter/deduped.rb