Class: FileCache

Inherits:
Object
  • Object
show all
Includes:
Rfix::Log
Defined in:
lib/rfix/file_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rfix::Log

#abort_box, #box, #current_path, #debug?, #debug_box, #div, #error_box, #fmt, #log_items, #margin, #new_line, #prt, #say, #say_abort, #say_debug, #say_error, #say_error_sub, #say_exit, #say_plain, #say_test, #strip, #test?, #unless_debug

Constructor Details

#initialize(path) ⇒ FileCache

Returns a new instance of FileCache.



5
6
7
8
9
# File 'lib/rfix/file_cache.rb', line 5

def initialize(path)
  @files = Hash.new
  @paths = Hash.new
  @root_path = path
end

Instance Attribute Details

#root_pathObject (readonly)

Returns the value of attribute root_path.



2
3
4
# File 'lib/rfix/file_cache.rb', line 2

def root_path
  @root_path
end

Instance Method Details

#add(file) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/rfix/file_cache.rb', line 11

def add(file)
  key = normalized_file_path(file)

  if @files.key?(key)
    return say_debug("File already exists with path {{error:#{file.path}}} using #{key}")
  end

  say_debug("Adding file with path {{green:#{file.path}}} using key {{info:#{key}}}")
  @files[key] = file
end

#get(path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rfix/file_cache.rb', line 22

def get(path)
  key = normalize_path(path)

  if file = @files[key]
    say_debug("Found file #{file} with path #{path}")
    return file
  end

  say_debug("Could {{error:NOT}} find path #{path}")
  nil
end

#pluck(&block) ⇒ Object



34
35
36
# File 'lib/rfix/file_cache.rb', line 34

def pluck(&block)
  @files.values.map(&block)
end