Class: FileRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/piggy-core/file_info.rb

Overview

A unordered list of FileInfos accessible by FileName. (Which means that you need both, path and name, to store the info in the repository. Unless DirectoryContents these files do not need to have a common location.)

Instance Method Summary collapse

Constructor Details

#initializeFileRepository

Returns a new instance of FileRepository.



199
200
201
# File 'lib/piggy-core/file_info.rb', line 199

def initialize
  @repository = Hash.new
end

Instance Method Details

#[]=(file_name, info) ⇒ Object



207
208
209
210
211
212
213
214
# File 'lib/piggy-core/file_info.rb', line 207

def []=(file_name, info)
  hash_or_nil =  @repository[file_name.path]
  if hash_or_nil == nil
    hash_or_nil = Hash.new
    @repository[file_name.path] = hash_or_nil
  end
  hash_or_nil[file_name.name] = info
end

#add(file_name) ⇒ Object



203
204
205
# File 'lib/piggy-core/file_info.rb', line 203

def add(file_name)
  self[file_name] = file_name
end

#get(file_name) ⇒ Object Also known as: [], has_key?



216
217
218
219
# File 'lib/piggy-core/file_info.rb', line 216

def get(file_name)
  sub_hash = @repository[file_name.path]
  return sub_hash == nil ? nil : sub_hash[file_name.name]
end