core-watch 0.0.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 742d61f2473ddb32defdf6b2379cf4bcb2c678ce889af2e2c8ae29b63548269b
4
- data.tar.gz: 72bfc097768d5abf52db5e4db2ca7828d2bb7d7013872bac622197e205529573
3
+ metadata.gz: b842f39a01164cc86186d2d6f4d460f072da58c49db6edfa16d1b539d7aebd23
4
+ data.tar.gz: b0793753ed9a521036bce634849297e8192a130afdf54c791c9110cda0065c5a
5
5
  SHA512:
6
- metadata.gz: 737bbeea342ae421335afc835826f515a60f441f0beb5e370c2e1c1f1389def2c466c1b895650806acb9bd3e4b87869f6046f02805c7d74a7bc3ab9eaf85641b
7
- data.tar.gz: e1725cf0a045c22d734b4819dfc9ccb0372864383e6adea88c0c2188d37ee39020087f8d8145f2ad2b6a1342779b21fe57c92dd7959c9f0ecb243f16c09e091a
6
+ metadata.gz: f811b6a0c04956fe4ecdf04739c56d4495dec0b3b637647007655dae6f04d4ff5c87ad2a0633f058780c6207d6abe6f0f945ff8912f98e4008a70d82a2bb8d4c
7
+ data.tar.gz: eb57fdb8e3185fe68f6fa69c47a97c13cdd15df6fb41767d6949da19af767e45bf6bba7263300f50a6f7c3e90c6ee54da44e9f5d3df70e1c515368d95cfc162b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## [v0.2.0](https://github.com/metabahn/corerb/releases/tag/2021-07-15)
2
+
3
+ *released on 2021-07-15*
4
+
5
+ * `add` [#56](https://github.com/metabahn/corerb/pull/56) Make all watch objects inspectable ([bryanp](https://github.com/bryanp))
6
+
7
+ ## [v0.1.0](https://github.com/metabahn/corerb/releases/tag/2021-07-07)
8
+
9
+ *released on 2021-07-07*
10
+
11
+ * `chg` [#45](https://github.com/metabahn/corerb/pull/45) Drop Ruby 2.6 support from core-watch ([bryanp](https://github.com/bryanp))
12
+
13
+ ## [v0.0.2](https://github.com/metabahn/corerb/releases/tag/2021-05-22)
14
+
15
+ *released on 2021-05-22*
16
+
17
+ * `chg` [#30](https://github.com/metabahn/corerb/pull/30) Performance improvements to watch snapshots ([bryanp](https://github.com/bryanp))
18
+
1
19
  ## [v0.0.0](https://github.com/metabahn/corerb/releases/tag/2021-04-03)
2
20
 
3
21
  *released on 2021-04-03*
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "is/inspectable"
4
+
3
5
  module Core
4
6
  module Watch
5
7
  # [public] Callback for a watched system.
@@ -22,6 +24,8 @@ module Core
22
24
  end
23
25
  end
24
26
 
27
+ include Is::Inspectable
28
+
25
29
  def initialize(&block)
26
30
  @block = block
27
31
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "is/inspectable"
3
4
  require "pathname"
4
5
 
5
6
  module Core
@@ -8,6 +9,8 @@ module Core
8
9
  # [public] Callback that wraps a path.
9
10
  #
10
11
  class Path < Callback
12
+ include Is::Inspectable
13
+
11
14
  def initialize(value, **kwargs, &block)
12
15
  super(**kwargs, &block)
13
16
 
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "is/inspectable"
4
+
3
5
  module Core
4
6
  module Watch
5
7
  module Callbacks
6
8
  # [public] Callback that wraps a regular expression.
7
9
  #
8
10
  class Regexp < Callback
11
+ include Is::Inspectable
12
+
9
13
  def initialize(regexp, **kwargs, &block)
10
14
  super(**kwargs, &block)
11
15
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "is/inspectable"
3
4
  require "pathname"
4
5
 
5
6
  module Core
@@ -7,6 +8,8 @@ module Core
7
8
  # [public] Contains changes to a watched system, organized by operation.
8
9
  #
9
10
  class Diff
11
+ include Is::Inspectable
12
+
10
13
  OPERATIONS = %i[added changed removed].freeze
11
14
 
12
15
  def initialize
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "is/inspectable"
4
+
3
5
  require_relative "diff"
4
6
 
5
7
  module Core
@@ -15,10 +17,11 @@ module Core
15
17
  end
16
18
  end
17
19
 
20
+ include Is::Inspectable
21
+
18
22
  def initialize(*paths, ignore: [], strategy: self.class.default_strategy)
19
23
  @ignore = ignore
20
- @directories = {}
21
- @files = {}
24
+ @watched = {}
22
25
  @strategy = strategy.new
23
26
 
24
27
  track(*paths)
@@ -39,35 +42,33 @@ module Core
39
42
  untrackable = []
40
43
  diff = Diff.new
41
44
 
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
45
+ @watched.each do |path, object|
46
+ case object[:type]
47
+ when :directory
48
+ # The mtime of the parent directory changes when its contents have changed (e.g. a file is added or removed).
49
+ # So, do the minimum amount of work necessary to detect added/removed files, then detect file changes below.
50
+ #
51
+ if @strategy.identify(path) != object[:identity]
52
+ path.glob("*") do |each_path|
53
+ unless @watched.include?(each_path)
54
+ next if ignore?(each_path)
55
+
56
+ diff.added(each_path)
57
+ trackable << each_path
58
+ end
56
59
  end
57
- end
58
-
59
- trackable << path
60
- end
61
- end
62
60
 
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
61
+ trackable << path
62
+ end
63
+ when :file
64
+ if @strategy.identify(path) != object[:identity]
65
+ diff.changed(path)
66
+ trackable << path
67
+ end
70
68
  end
69
+ rescue Errno::ENOENT
70
+ diff.removed(path)
71
+ untrackable << path
71
72
  end
72
73
 
73
74
  track(*trackable)
@@ -82,13 +83,22 @@ module Core
82
83
  paths.each do |path|
83
84
  next if ignore?(path)
84
85
 
85
- if path.file?
86
- @files[path] = @strategy.identify(path)
86
+ type = if path.file?
87
+ :file
87
88
  elsif path.directory?
88
- existed = @directories.include?(path)
89
- @directories[path] = @strategy.identify(path)
89
+ :directory
90
+ end
91
+
92
+ if type
93
+ object = {
94
+ type: type,
95
+ identity: @strategy.identify(path)
96
+ }
97
+
98
+ existed = @watched.include?(path)
99
+ @watched[path] = object
90
100
 
91
- unless existed
101
+ if type == :directory && !existed
92
102
  track(*path.glob("*"))
93
103
  end
94
104
  else
@@ -101,8 +111,7 @@ module Core
101
111
  #
102
112
  private def untrack(*paths)
103
113
  paths.each do |path|
104
- @files.delete(path)
105
- @directories.delete(path)
114
+ @watched.delete(path)
106
115
  end
107
116
  end
108
117
  end
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "is/inspectable"
4
+
3
5
  module Core
4
6
  module Watch
5
7
  # [public] The status of a system watch.
6
8
  #
7
9
  class Status
10
+ include Is::Inspectable
11
+ inspects without: [:@mutex]
12
+
8
13
  STATES = %i[running paused stopped].freeze
9
14
 
10
15
  def initialize
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "is/inspectable"
3
4
  require "openssl"
4
5
 
5
6
  require_relative "../strategy"
@@ -10,6 +11,8 @@ module Core
10
11
  # [public] Identifies a path by digest or modified time (for directories).
11
12
  #
12
13
  class Digest
14
+ include Is::Inspectable
15
+
13
16
  BUFFER_LENGTH = 16_384
14
17
 
15
18
  # [public]
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "is/inspectable"
4
+
3
5
  require_relative "../strategy"
4
6
 
5
7
  module Core
@@ -8,6 +10,8 @@ module Core
8
10
  # [public] Identifies a path by modified time.
9
11
  #
10
12
  class Timestamp
13
+ include Is::Inspectable
14
+
11
15
  # [public]
12
16
  #
13
17
  def identify(path)
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "is/inspectable"
4
+
3
5
  module Core
4
6
  module Watch
5
7
  # [public] Abstract strategy for uniquely identifying a path.
6
8
  #
7
9
  class Strategy
10
+ include Is::Inspectable
11
+
8
12
  # [public]
9
13
  #
10
14
  def identify(path)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "is/inspectable"
3
4
  require "pathname"
4
5
 
5
6
  require "core/async"
@@ -14,6 +15,8 @@ module Core
14
15
  #
15
16
  class System
16
17
  include Is::Async
18
+ include Is::Inspectable
19
+ inspects without: [:@mutex, :@working]
17
20
 
18
21
  # [public] The configured polling interval.
19
22
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Watch
5
- VERSION = "0.0.0"
5
+ VERSION = "0.2.1"
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.0
4
+ version: 0.2.1
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-04-04 00:00:00.000000000 Z
11
+ date: 2021-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-async
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.0
19
+ version: '0.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.0
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: core-inspect
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.0'
27
41
  description: Watches the filesystem for changes.
28
42
  email: bryan@metabahn.com
29
43
  executables: []
@@ -56,14 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
70
  requirements:
57
71
  - - ">="
58
72
  - !ruby/object:Gem::Version
59
- version: 2.5.0
73
+ version: '2.7'
60
74
  required_rubygems_version: !ruby/object:Gem::Requirement
61
75
  requirements:
62
76
  - - ">="
63
77
  - !ruby/object:Gem::Version
64
78
  version: '0'
65
79
  requirements: []
66
- rubygems_version: 3.2.4
80
+ rubygems_version: 3.2.15
67
81
  signing_key:
68
82
  specification_version: 4
69
83
  summary: Watches the filesystem for changes.