Class: Cache

Inherits:
Hash
  • Object
show all
Defined in:
lib/droxi/cache.rb

Overview

Special Hash of remote file paths to cached file metadata.

Instance Method Summary collapse

Instance Method Details

#add(metadata) ⇒ Object

Add a metadata Hash and its contents to the Cache and return the Cache.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/droxi/cache.rb', line 5

def add()
  path = ['path'].downcase
  store(path, )
  dirname = File.dirname(path)
  if dirname != path
    contents = fetch(dirname, {}).fetch('contents', nil)
    contents <<  if contents && !contents.include?()
  end
  return self unless .include?('contents')
  ['contents'].each { |content| add(content) }
  self
end

#full_info?(path, require_contents = true) ⇒ Boolean

Return true if the path’s information is cached, false otherwise.

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/droxi/cache.rb', line 28

def full_info?(path, require_contents = true)
  path = path.downcase
  info = fetch(path, nil)
  info && (!require_contents || !info['is_dir'] || info.include?('contents'))
end

#remove(path) ⇒ Object

Remove a path’s metadata from the Cache and return the Cache.



19
20
21
22
23
24
25
# File 'lib/droxi/cache.rb', line 19

def remove(path)
  path = path.downcase
  recursive_remove(path)
  contents = fetch(File.dirname(path), {}).fetch('contents', nil)
  contents.delete_if { |item| item['path'].downcase == path } if contents
  self
end