Class: FileWatch::WatchedFilesCollection
- Inherits:
-
Object
- Object
- FileWatch::WatchedFilesCollection
- Defined in:
- lib/filewatch/watched_files_collection.rb
Instance Method Summary collapse
- #add(watched_file) ⇒ Object
- #close_all ⇒ Object
- #delete(paths) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(settings) ⇒ WatchedFilesCollection
constructor
A new instance of WatchedFilesCollection.
- #keys ⇒ Object
- #values ⇒ Object
- #watched_file_by_path(path) ⇒ Object
Constructor Details
#initialize(settings) ⇒ WatchedFilesCollection
Returns a new instance of WatchedFilesCollection.
5 6 7 8 9 10 11 |
# File 'lib/filewatch/watched_files_collection.rb', line 5 def initialize(settings) @sort_by = settings.file_sort_by # "last_modified" | "path" @sort_direction = settings.file_sort_direction # "asc" | "desc" @sort_method = method("#{@sort_by}_#{@sort_direction}".to_sym) @files = [] @pointers = {} end |
Instance Method Details
#add(watched_file) ⇒ Object
13 14 15 16 |
# File 'lib/filewatch/watched_files_collection.rb', line 13 def add(watched_file) @files << watched_file @sort_method.call end |
#close_all ⇒ Object
26 27 28 |
# File 'lib/filewatch/watched_files_collection.rb', line 26 def close_all @files.each(&:file_close) end |
#delete(paths) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/filewatch/watched_files_collection.rb', line 18 def delete(paths) Array(paths).each do |f| index = @pointers.delete(f) @files.delete_at(index) end @sort_method.call end |
#empty? ⇒ Boolean
30 31 32 |
# File 'lib/filewatch/watched_files_collection.rb', line 30 def empty? @files.empty? end |
#keys ⇒ Object
34 35 36 |
# File 'lib/filewatch/watched_files_collection.rb', line 34 def keys @pointers.keys end |
#values ⇒ Object
38 39 40 |
# File 'lib/filewatch/watched_files_collection.rb', line 38 def values @files end |
#watched_file_by_path(path) ⇒ Object
42 43 44 45 46 |
# File 'lib/filewatch/watched_files_collection.rb', line 42 def watched_file_by_path(path) index = @pointers[path] return nil unless index @files[index] end |