Class: Zomgit::Persistor
- Inherits:
-
Object
- Object
- Zomgit::Persistor
- Includes:
- Singleton
- Defined in:
- lib/zomgit/persistor.rb
Constant Summary collapse
- RUNTIME_DIR =
File.(File.join(ENV["HOME"], ".zomgit"))
- INDEXES_DIR =
File.join(RUNTIME_DIR, "indexes")
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#index_file ⇒ Object
readonly
Returns the value of attribute index_file.
-
#indexed ⇒ Object
(also: #indexed?)
readonly
Returns the value of attribute indexed.
Instance Method Summary collapse
- #cache_index(files) ⇒ Object
- #clean_index_cache! ⇒ Object
-
#initialize ⇒ Persistor
constructor
A new instance of Persistor.
Constructor Details
#initialize ⇒ Persistor
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
#index ⇒ Object (readonly)
Returns the value of attribute index.
6 7 8 |
# File 'lib/zomgit/persistor.rb', line 6 def index @index end |
#index_file ⇒ Object (readonly)
Returns the value of attribute index_file.
6 7 8 |
# File 'lib/zomgit/persistor.rb', line 6 def index_file @index_file end |
#indexed ⇒ Object (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 |