Class: Dotbox::Record
- Inherits:
-
Object
- Object
- Dotbox::Record
- Defined in:
- lib/dotbox/record.rb
Instance Method Summary collapse
- #[](path) ⇒ Object
- #add(file) ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ Record
constructor
A new instance of Record.
- #remove(file) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize ⇒ Record
Returns a new instance of Record.
7 8 9 10 11 12 13 14 |
# File 'lib/dotbox/record.rb', line 7 def initialize @record_file_path = "#{Config.new(Dotbox::CONFIG_FILE).value}/Apps/Dotbox/.dotbox" if !::File.exists?(@record_file_path) FileUtils.mkdir_p(::File.dirname(@record_file_path)) FileUtils.touch(@record_file_path) end @records = YAML.load_file(@record_file_path) || {} end |
Instance Method Details
#[](path) ⇒ Object
32 33 34 |
# File 'lib/dotbox/record.rb', line 32 def [](path) @records[path] end |
#add(file) ⇒ Object
16 17 18 19 |
# File 'lib/dotbox/record.rb', line 16 def add(file) @records[file.rel_path] = file.type save end |
#each ⇒ Object
36 37 38 39 40 |
# File 'lib/dotbox/record.rb', line 36 def each @records.each do |path, type| yield path end end |
#remove(file) ⇒ Object
21 22 23 24 |
# File 'lib/dotbox/record.rb', line 21 def remove(file) @records.delete file.rel_path save end |
#save ⇒ Object
26 27 28 29 30 |
# File 'lib/dotbox/record.rb', line 26 def save record_file = ::File.new(@record_file_path, 'w+') record_file.puts(YAML.dump(@records)) record_file.close end |