core-watch 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ed0f842d5e77d84a3a379c48ce82d1717485b56e2c33e5e6a86fcfae69f58b4
4
- data.tar.gz: f75240b2e82db55ed719ef18711ddd36501b528f27d16f28a01a8097118cf21e
3
+ metadata.gz: 7214e1588d42429020551b10a17cb1259b66b7a794589b4d0048403abb3da14d
4
+ data.tar.gz: e3437fc62e1d34e5c9e8ce3429d3dc2f07d1a7b7bf5f57c87df16b7a43802819
5
5
  SHA512:
6
- metadata.gz: 14ce6c0d7b2333652ec3a4d15cc885e7d88765a04bd5b6d93acf1a9985507b94f169510b6c4a8fc90a42daef22ef3c592fa44b48804ce4ab32f20372161f1adc
7
- data.tar.gz: fd21f2387f8458c9ff96586c2e91640a2123810dc91b91393b03edea85644238f8096001e3bff5c53770cb9c04d05f24eb9e2800d812d155e256a6187cdebb3d
6
+ metadata.gz: 57964374546b40461c94a72f958b7e5e3e3df4f3fa7503f3063a8062de789cd3e6553f7456b05fda072da746b27db1b73c77acd445e3386198e4694ea73b3a46
7
+ data.tar.gz: 46c5c6a2e0dd0a9203729c2c719ff004f03bacd60f08fac8c1d678c3a471d62bf67c741fd19f10a527a388be9328f0547d5631da3d94052c8572fcfc2d3c66bd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [v0.0.2](https://github.com/metabahn/corerb/releases/tag/2021-05-22)
2
+
3
+ *released on 2021-05-22*
4
+
5
+ * `chg` [#30](https://github.com/metabahn/corerb/pull/30) Performance improvements to watch snapshots ([bryanp](https://github.com/bryanp))
6
+
1
7
  ## [v0.0.0](https://github.com/metabahn/corerb/releases/tag/2021-04-03)
2
8
 
3
9
  *released on 2021-04-03*
@@ -17,8 +17,7 @@ module Core
17
17
 
18
18
  def initialize(*paths, ignore: [], strategy: self.class.default_strategy)
19
19
  @ignore = ignore
20
- @directories = {}
21
- @files = {}
20
+ @watched = {}
22
21
  @strategy = strategy.new
23
22
 
24
23
  track(*paths)
@@ -39,35 +38,33 @@ module Core
39
38
  untrackable = []
40
39
  diff = Diff.new
41
40
 
42
- # The mtime of the parent directory changes when its contents have changed (e.g. a file is added or removed).
43
- # So, do the minimum amount of work necessary to detect added/removed files, then detect file changes below.
44
- #
45
- @directories.each do |path, current|
46
- if !path.exist?
47
- diff.removed(path)
48
- untrackable << path
49
- elsif @strategy.identify(path) != current
50
- path.glob("*") do |each_path|
51
- unless @directories.include?(each_path) || @files.include?(each_path)
52
- next if ignore?(each_path)
53
-
54
- diff.added(each_path)
55
- trackable << each_path
41
+ @watched.each do |path, object|
42
+ case object[:type]
43
+ when :directory
44
+ # The mtime of the parent directory changes when its contents have changed (e.g. a file is added or removed).
45
+ # So, do the minimum amount of work necessary to detect added/removed files, then detect file changes below.
46
+ #
47
+ if @strategy.identify(path) != object[:identity]
48
+ path.glob("*") do |each_path|
49
+ unless @watched.include?(each_path)
50
+ next if ignore?(each_path)
51
+
52
+ diff.added(each_path)
53
+ trackable << each_path
54
+ end
56
55
  end
57
- end
58
56
 
59
- trackable << path
60
- end
61
- end
62
-
63
- @files.each do |path, current|
64
- if !path.exist?
65
- diff.removed(path)
66
- untrackable << path
67
- elsif @strategy.identify(path) != current
68
- diff.changed(path)
69
- trackable << path
57
+ trackable << path
58
+ end
59
+ when :file
60
+ if @strategy.identify(path) != object[:identity]
61
+ diff.changed(path)
62
+ trackable << path
63
+ end
70
64
  end
65
+ rescue Errno::ENOENT
66
+ diff.removed(path)
67
+ untrackable << path
71
68
  end
72
69
 
73
70
  track(*trackable)
@@ -82,13 +79,22 @@ module Core
82
79
  paths.each do |path|
83
80
  next if ignore?(path)
84
81
 
85
- if path.file?
86
- @files[path] = @strategy.identify(path)
82
+ type = if path.file?
83
+ :file
87
84
  elsif path.directory?
88
- existed = @directories.include?(path)
89
- @directories[path] = @strategy.identify(path)
85
+ :directory
86
+ end
87
+
88
+ if type
89
+ object = {
90
+ type: type,
91
+ identity: @strategy.identify(path)
92
+ }
93
+
94
+ existed = @watched.include?(path)
95
+ @watched[path] = object
90
96
 
91
- unless existed
97
+ if type == :directory && !existed
92
98
  track(*path.glob("*"))
93
99
  end
94
100
  else
@@ -101,8 +107,7 @@ module Core
101
107
  #
102
108
  private def untrack(*paths)
103
109
  paths.each do |path|
104
- @files.delete(path)
105
- @directories.delete(path)
110
+ @watched.delete(path)
106
111
  end
107
112
  end
108
113
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Watch
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
6
6
 
7
7
  def self.version
8
8
  VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core-watch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-20 00:00:00.000000000 Z
11
+ date: 2021-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-async