Class: Listen::File
- Inherits:
-
Object
- Object
- Listen::File
- Defined in:
- lib/listen/file.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#_content_modified? ⇒ Boolean
private
Only useful on Darwin because of the file mtime second precision.
- #_exist? ⇒ Boolean private
- #_existing_path? ⇒ Boolean private
- #_lstat ⇒ Object private
- #_md5 ⇒ Object private
- #_mode ⇒ Object private
- #_mode_modified? ⇒ Boolean private
- #_modified? ⇒ Boolean private
- #_mtime ⇒ Object private
-
#_new_data ⇒ Object
private
Only Darwin need md5 comparaison because of the file mtime second precision.
- #_new_path? ⇒ Boolean private
- #_record ⇒ Object private
- #_record_data ⇒ Object private
- #_record_data? ⇒ Boolean private
- #_removed_path? ⇒ Boolean private
- #_set_record_data ⇒ Object private
- #_unset_record_data ⇒ Object private
- #change ⇒ Object
-
#initialize(path) ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize(path) ⇒ File
Returns a new instance of File.
5 6 7 8 |
# File 'lib/listen/file.rb', line 5 def initialize(path) @path = path @data = { type: 'File' } end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/listen/file.rb', line 3 def data @data end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/listen/file.rb', line 3 def path @path end |
Instance Method Details
#_content_modified? ⇒ Boolean (private)
Only useful on Darwin because of the file mtime second precision
55 56 57 |
# File 'lib/listen/file.rb', line 55 def _content_modified? _record_data[:md5] && _md5 != _record_data[:md5] end |
#_exist? ⇒ Boolean (private)
41 42 43 |
# File 'lib/listen/file.rb', line 41 def _exist? @exist ||= ::File.exist?(path) end |
#_existing_path? ⇒ Boolean (private)
29 30 31 |
# File 'lib/listen/file.rb', line 29 def _existing_path? _exist? && _record_data? end |
#_lstat ⇒ Object (private)
96 97 98 99 100 |
# File 'lib/listen/file.rb', line 96 def _lstat @lstat ||= ::File.lstat(path) rescue nil end |
#_md5 ⇒ Object (private)
102 103 104 105 106 |
# File 'lib/listen/file.rb', line 102 def _md5 @md5 ||= Digest::MD5.file(path).digest rescue nil end |
#_mode ⇒ Object (private)
90 91 92 93 94 |
# File 'lib/listen/file.rb', line 90 def _mode @mode ||= _lstat.mode rescue nil end |
#_mode_modified? ⇒ Boolean (private)
49 50 51 |
# File 'lib/listen/file.rb', line 49 def _mode_modified? _mode != _record_data[:mode] end |
#_modified? ⇒ Boolean (private)
45 46 47 |
# File 'lib/listen/file.rb', line 45 def _modified? _mtime > _record_data[:mtime] || _mode_modified? || _content_modified? end |
#_mtime ⇒ Object (private)
84 85 86 87 88 |
# File 'lib/listen/file.rb', line 84 def _mtime @mtime ||= _lstat.mtime.to_f rescue 0.0 end |
#_new_data ⇒ Object (private)
Only Darwin need md5 comparaison because of the file mtime second precision
70 71 72 73 74 |
# File 'lib/listen/file.rb', line 70 def _new_data data = { mtime: _mtime, mode: _mode } data[:md5] = _md5 if RbConfig::CONFIG['target_os'] =~ /darwin/i data end |
#_new_path? ⇒ Boolean (private)
25 26 27 |
# File 'lib/listen/file.rb', line 25 def _new_path? _exist? && !_record_data? end |
#_record ⇒ Object (private)
80 81 82 |
# File 'lib/listen/file.rb', line 80 def _record Celluloid::Actor[:listen_record] end |
#_record_data ⇒ Object (private)
76 77 78 |
# File 'lib/listen/file.rb', line 76 def _record_data @_record_data ||= _record.future.file_data(path).value end |
#_record_data? ⇒ Boolean (private)
37 38 39 |
# File 'lib/listen/file.rb', line 37 def _record_data? !_record_data.empty? end |
#_removed_path? ⇒ Boolean (private)
33 34 35 |
# File 'lib/listen/file.rb', line 33 def _removed_path? !_exist? end |
#_set_record_data ⇒ Object (private)
59 60 61 62 |
# File 'lib/listen/file.rb', line 59 def _set_record_data @data.merge!(_new_data) _record.async.set_path(path, data) end |
#_unset_record_data ⇒ Object (private)
64 65 66 |
# File 'lib/listen/file.rb', line 64 def _unset_record_data _record.async.unset_path(path) end |
#change ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/listen/file.rb', line 10 def change if _existing_path? && _modified? _set_record_data :modified elsif _new_path? _set_record_data :added elsif _removed_path? _unset_record_data :removed end end |