Class: Listen::Directory
- Inherits:
-
Object
- Object
- Listen::Directory
- Defined in:
- lib/listen/directory.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #_all_entries ⇒ Object private
- #_async_change(entry_path, options) ⇒ Object private
- #_change_pool ⇒ Object private
- #_entries ⇒ Object private
- #_entry_type(entry_path) ⇒ Object private
- #_record ⇒ Object private
- #_record_entries ⇒ Object private
- #_recursive_scan?(path) ⇒ Boolean private
- #_update_record ⇒ Object private
-
#initialize(path, options = {}) ⇒ Directory
constructor
A new instance of Directory.
- #scan ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Directory
Returns a new instance of Directory.
5 6 7 8 |
# File 'lib/listen/directory.rb', line 5 def initialize(path, = {}) @path = path @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/listen/directory.rb', line 3 def @options end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/listen/directory.rb', line 3 def path @path end |
Instance Method Details
#_all_entries ⇒ Object (private)
31 32 33 |
# File 'lib/listen/directory.rb', line 31 def _all_entries _record_entries.merge(_entries) end |
#_async_change(entry_path, options) ⇒ Object (private)
68 69 70 71 |
# File 'lib/listen/directory.rb', line 68 def _async_change(entry_path, ) entry_path = path.join(entry_path) _change_pool.async.change(entry_path, ) end |
#_change_pool ⇒ Object (private)
60 61 62 |
# File 'lib/listen/directory.rb', line 60 def _change_pool Celluloid::Actor[:listen_change_pool] end |
#_entries ⇒ Object (private)
35 36 37 38 39 40 |
# File 'lib/listen/directory.rb', line 35 def _entries return {} unless ::Dir.exists?(path) entries = ::Dir.entries(path) - %w[. ..] entries = entries.map { |entry| [entry, type: _entry_type(entry)] } Hash[*entries.flatten] end |
#_entry_type(entry_path) ⇒ Object (private)
42 43 44 45 46 47 48 49 |
# File 'lib/listen/directory.rb', line 42 def _entry_type(entry_path) entry_path = path.join(entry_path) if entry_path.file? 'File' elsif entry_path.directory? 'Dir' end end |
#_record ⇒ Object (private)
56 57 58 |
# File 'lib/listen/directory.rb', line 56 def _record Celluloid::Actor[:listen_record] end |
#_record_entries ⇒ Object (private)
51 52 53 54 |
# File 'lib/listen/directory.rb', line 51 def _record_entries future = _record.future.dir_entries(path) future.value end |
#_recursive_scan?(path) ⇒ Boolean (private)
64 65 66 |
# File 'lib/listen/directory.rb', line 64 def _recursive_scan?(path) !::Dir.exists?(path) || [:recursive] end |
#_update_record ⇒ Object (private)
23 24 25 26 27 28 29 |
# File 'lib/listen/directory.rb', line 23 def _update_record if ::Dir.exists?(path) _record.async.set_path(path, { type: 'Dir'}) else _record.async.unset_path(path) end end |
#scan ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/listen/directory.rb', line 10 def scan _update_record _all_entries.each do |entry_path, data| case data[:type] when 'File' then _async_change(entry_path, .merge(type: 'File')) when 'Dir' _async_change(entry_path, .merge(type: 'Dir')) if _recursive_scan?(entry_path) end end end |