irb-reload 0.1.1 → 0.1.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: 3c9e5e8c284ad8d612479af2311030ef75e3278833ed03d4496e3db4d0b812e3
4
- data.tar.gz: ce198ef59ecfcc288c8d5dc6391dd7c647745a61d76942bd337fd791927e5720
3
+ metadata.gz: f86b968360d8b04e1a9e4b3de43903209b9b33f86607fc274bf4678610012303
4
+ data.tar.gz: 37a452296c72d81e3c512b89d5325ab200d620e8bd181f997864dd4944b0de15
5
5
  SHA512:
6
- metadata.gz: c7314d14d35c391de669282744c0779fc85a456c7fee952b86af0d4bf14535b3aa04168b95ef2d830dd0c09dc3b7f63ff8f79aa215af75c110e5cb849dd4cdbf
7
- data.tar.gz: 912492fe22aa8df900b9444cd0ddcf2dce72a7afa53ca3ca8ba600831b9cc82408881a37ad1c3a37cd1f3bedb9ecabd622fb2b4ace9aa1aa56fe35e6c919ada3
6
+ metadata.gz: 9eea4489ae2b03e40fee2a19efedd8fabb9ed6b140748bc68711e384561f236fb5c690c6337ebe116afb6b332e096cb52daf410577d55a7b9974927a626867c7
7
+ data.tar.gz: d7eddd3543f1f508b705fa62bce976a710db463b168bd20bf858cde2759eeceef1c0b278c995acc84b01442d7a4c641fbf0d48fc40790a8c138e7714c6b04c53
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 4.0.1
data/README.md CHANGED
@@ -32,12 +32,9 @@ You can tweak the watcher through `IRB.conf`.
32
32
  ```ruby
33
33
  IRB.conf[:RELOAD] = {
34
34
  paths: %w[app lib], # directories to watch. Default is `lib`.
35
- listen: { latency: 0.2 }, # options forwarded to Listen
36
35
  }
37
36
  ```
38
37
 
39
- Any keys under `:listen` are passed straight to `Listen.to`. Use this to change latency, polling, or ignore patterns.
40
-
41
38
  ## Development
42
39
 
43
40
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to execute the test suite. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module IRB
4
4
  module Reload
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
data/lib/irb/reload.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "irb"
4
- require "listen"
4
+ require "set"
5
+ require "watchcat"
5
6
 
6
7
  require_relative "reload/version"
7
8
  require_relative "reload/command"
@@ -10,18 +11,22 @@ module IRB
10
11
  module Reload
11
12
  DEFAULT_PATTERN = /\.rb\z/.freeze
12
13
  DEFAULT_PATHS = ["lib"]
14
+ WATCHCAT_FILTERS = {
15
+ ignore_remove: true,
16
+ ignore_access: true
17
+ }.freeze
13
18
 
14
19
  class << self
15
20
  def start
16
21
  @changed_files = Set.new
17
22
  normalized_paths = normalize_paths(config[:paths] || DEFAULT_PATHS)
18
- listener_options = default_listen_option
19
23
 
20
- @listener = Listen.to(*normalized_paths, **listener_options) do |modified, added, _removed|
21
- record_changed_files(modified, added)
24
+ @watcher&.stop if defined?(@watcher) && @watcher
25
+ @watcher = Watchcat.watch(normalized_paths, filters: WATCHCAT_FILTERS) do |event|
26
+ record_watchcat_event(event)
22
27
  end
23
28
 
24
- @listener.start
29
+ @watched_paths = normalized_paths
25
30
  true
26
31
  end
27
32
 
@@ -33,9 +38,7 @@ module IRB
33
38
  end
34
39
 
35
40
  def watched_paths
36
- return [] unless @listener
37
-
38
- @listener.respond_to?(:directories) ? @listener.directories : []
41
+ @watched_paths || []
39
42
  end
40
43
 
41
44
  def config
@@ -44,13 +47,6 @@ module IRB
44
47
 
45
48
  private
46
49
 
47
- def default_listen_option
48
- options = { only: DEFAULT_PATTERN }
49
- config_options = config.fetch(:listen, {})
50
- options.merge!(symbolize_keys(config_options))
51
- options
52
- end
53
-
54
50
  def normalize_paths(paths)
55
51
  normalized = Array(paths).map(&:to_s).reject(&:empty?)
56
52
  normalized = [Dir.pwd] if normalized.empty?
@@ -66,6 +62,24 @@ module IRB
66
62
  end
67
63
  end
68
64
 
65
+ def record_watchcat_event(event)
66
+ return unless actionable_event?(event)
67
+
68
+ paths = Array(event.paths)
69
+ if event.kind.create?
70
+ record_changed_files([], paths)
71
+ else
72
+ record_changed_files(paths, [])
73
+ end
74
+ end
75
+
76
+ def actionable_event?(event)
77
+ kind = event&.kind
78
+ return false unless kind
79
+
80
+ kind.create? || kind.modify? || kind.any?
81
+ end
82
+
69
83
  def ruby_file?(file)
70
84
  File.extname(file) == ".rb"
71
85
  end
@@ -83,12 +97,6 @@ module IRB
83
97
  ensure
84
98
  $VERBOSE = old_verbose
85
99
  end
86
-
87
- def symbolize_keys(hash)
88
- hash.each_with_object({}) do |(key, value), memo|
89
- memo[key.to_sym] = value
90
- end
91
- end
92
100
  end
93
101
  end
94
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb-reload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Yaginuma
@@ -24,39 +24,26 @@ dependencies:
24
24
  - !ruby/object:Gem::Version
25
25
  version: '1.13'
26
26
  - !ruby/object:Gem::Dependency
27
- name: listen
27
+ name: watchcat
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '3.8'
32
+ version: '0.5'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '3.8'
40
- - !ruby/object:Gem::Dependency
41
- name: logger
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: '0'
47
- type: :runtime
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: '0'
39
+ version: '0.5'
54
40
  email:
55
41
  - yuuji.yaginuma@gmail.com
56
42
  executables: []
57
43
  extensions: []
58
44
  extra_rdoc_files: []
59
45
  files:
46
+ - ".ruby-version"
60
47
  - CODE_OF_CONDUCT.md
61
48
  - LICENSE.txt
62
49
  - README.md