Sha256: b1bf0ded1202332803fe86287ff161244948a0a95842c502bbfde25cde287aef

Contents?: true

Size: 1.25 KB

Versions: 46

Compression:

Stored size: 1.25 KB

Contents

require 'pathname'

class Cache_Helper

  def cache_exists?
    File.directory?(dir + '/.onceover')
  end

  def self.digest(path, opts = {
    exceptions: ['.','..','.onceover']
    })
    if File.directory?(path)
      # Get the list of files
      children = Cache_Helper.get_children(path, opts[:exceptions])
    else
      children = [File.expand_path(path)]
    end

    # Calculate hashes
    hashes = children.map do |child_path|
      if File.directory? child_path
        :directory
      else
        Digest::MD5.file(child_path)
      end
    end

    root = Pathname.new(File.expand_path(path))
    # Move pathnames back to relative
    children.map! do |child_path|
      Pathname.new(child_path).relative_path_from root
    end
    Hash[children.zip(hashes)]
  end

  def self.get_children(dir, exclusions)
    root_files = []
    files      = []
    Dir.chdir(dir) do
      # Get all root files
      root_files = Dir.glob('*',File::FNM_DOTMATCH)
      root_files = root_files - exclusions
      root_files.each do |file|
        files << file
        files << Dir.glob("#{file}/**/*",File::FNM_DOTMATCH)
      end
      files.flatten!
      # Calculate absolue paths
      files.map! do |file|
        File.expand_path(file)
      end
    end
    files
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
onceover-3.22.0 features/support/cache_helper.rb
onceover-3.21.0 features/support/cache_helper.rb
onceover-3.20.0 features/support/cache_helper.rb
onceover-3.19.2 features/support/cache_helper.rb
onceover-3.19.1 features/support/cache_helper.rb
onceover-3.19.0 features/support/cache_helper.rb
onceover-3.18.1 features/support/cache_helper.rb
onceover-3.18.0 features/support/cache_helper.rb
onceover-3.17.3 features/support/cache_helper.rb
onceover-3.17.2 features/support/cache_helper.rb
onceover-3.17.1 features/support/cache_helper.rb
onceover-3.17.0 features/support/cache_helper.rb
onceover-3.16.0 features/support/cache_helper.rb
onceover-3.15.2 features/support/cache_helper.rb
onceover-3.15.1 features/support/cache_helper.rb
onceover-3.15.0 features/support/cache_helper.rb
onceover-3.14.1 features/support/cache_helper.rb
onceover-3.14.0 features/support/cache_helper.rb
onceover-3.13.4 features/support/cache_helper.rb
onceover-3.13.3 features/support/cache_helper.rb