Class: Zomgit::Persistor

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/zomgit/persistor.rb

Constant Summary collapse

RUNTIME_DIR =
File.expand_path(File.join(ENV["HOME"], ".zomgit"))
INDEXES_DIR =
File.join(RUNTIME_DIR, "indexes")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePersistor

Returns a new instance of Persistor.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/zomgit/persistor.rb', line 14

def initialize
  unless File.directory?(RUNTIME_DIR)
    FileUtils.mkdir_p([RUNTIME_DIR, INDEXES_DIR])
  end

  if File.file?(self.index_file)
    @index = File.read(self.index_file).split("\n")
    @indexed = true
  else
    @index = []
    @indexed = false
  end
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'lib/zomgit/persistor.rb', line 6

def index
  @index
end

#index_fileObject (readonly)

Returns the value of attribute index_file.



6
7
8
# File 'lib/zomgit/persistor.rb', line 6

def index_file
  @index_file
end

#indexedObject (readonly) Also known as: indexed?

Returns the value of attribute indexed.



6
7
8
# File 'lib/zomgit/persistor.rb', line 6

def indexed
  @indexed
end

Instance Method Details

#cache_index(files) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/zomgit/persistor.rb', line 28

def cache_index(files)
  @index = files

  File.open(self.index_file, "wb") { |f| f.puts files.join("\n") }

  @indexed = true
end

#clean_index_cache!Object



36
37
38
39
40
41
# File 'lib/zomgit/persistor.rb', line 36

def clean_index_cache!
  if self.indexed?
    File.unlink(self.index_file)
    @indexed = false
  end
end