irb-reload 0.1.1 → 0.1.3

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: 71619300fd24b66bd53ec9266316e9678790749c14588fdd26244a1554a1975b
4
+ data.tar.gz: 904ea7d45579041615589de737b224832066e993343a1ede37dce3a0beea0a62
5
5
  SHA512:
6
- metadata.gz: c7314d14d35c391de669282744c0779fc85a456c7fee952b86af0d4bf14535b3aa04168b95ef2d830dd0c09dc3b7f63ff8f79aa215af75c110e5cb849dd4cdbf
7
- data.tar.gz: 912492fe22aa8df900b9444cd0ddcf2dce72a7afa53ca3ca8ba600831b9cc82408881a37ad1c3a37cd1f3bedb9ecabd622fb2b4ace9aa1aa56fe35e6c919ada3
6
+ metadata.gz: c5de731087b4c326347d636f61b807d143b92f0742e9570c813b8e1d1d7dad22dbe31ce3ff17a597058dc37e2b8d6596753cd3fb8284669658b67aafaeba3abd
7
+ data.tar.gz: e74904b0e2f0e6104f96403194f39711d5552f6f207fce4b1749413115414e071447e72b06c6772cbea29845803de14d677d0381ce42b41ebae2ff51199645c4
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.3"
6
6
  end
7
7
  end
data/lib/irb/reload.rb CHANGED
@@ -1,27 +1,31 @@
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"
8
9
 
9
10
  module IRB
10
11
  module Reload
11
- DEFAULT_PATTERN = /\.rb\z/.freeze
12
12
  DEFAULT_PATHS = ["lib"]
13
+ WATCHCAT_FILTERS = {
14
+ ignore_remove: true,
15
+ ignore_access: true
16
+ }.freeze
13
17
 
14
18
  class << self
15
19
  def start
16
20
  @changed_files = Set.new
17
21
  normalized_paths = normalize_paths(config[:paths] || DEFAULT_PATHS)
18
- listener_options = default_listen_option
19
22
 
20
- @listener = Listen.to(*normalized_paths, **listener_options) do |modified, added, _removed|
21
- record_changed_files(modified, added)
23
+ @watcher&.stop if defined?(@watcher) && @watcher
24
+ @watcher = Watchcat.watch(normalized_paths, filters: WATCHCAT_FILTERS) do |event|
25
+ record_watchcat_event(event)
22
26
  end
23
27
 
24
- @listener.start
28
+ @watched_paths = normalized_paths
25
29
  true
26
30
  end
27
31
 
@@ -33,9 +37,7 @@ module IRB
33
37
  end
34
38
 
35
39
  def watched_paths
36
- return [] unless @listener
37
-
38
- @listener.respond_to?(:directories) ? @listener.directories : []
40
+ @watched_paths || []
39
41
  end
40
42
 
41
43
  def config
@@ -44,13 +46,6 @@ module IRB
44
46
 
45
47
  private
46
48
 
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
49
  def normalize_paths(paths)
55
50
  normalized = Array(paths).map(&:to_s).reject(&:empty?)
56
51
  normalized = [Dir.pwd] if normalized.empty?
@@ -66,6 +61,24 @@ module IRB
66
61
  end
67
62
  end
68
63
 
64
+ def record_watchcat_event(event)
65
+ return unless actionable_event?(event)
66
+
67
+ paths = Array(event.paths)
68
+ if event.kind.create?
69
+ record_changed_files([], paths)
70
+ else
71
+ record_changed_files(paths, [])
72
+ end
73
+ end
74
+
75
+ def actionable_event?(event)
76
+ kind = event&.kind
77
+ return false unless kind
78
+
79
+ kind.create? || kind.modify? || kind.any?
80
+ end
81
+
69
82
  def ruby_file?(file)
70
83
  File.extname(file) == ".rb"
71
84
  end
@@ -83,12 +96,6 @@ module IRB
83
96
  ensure
84
97
  $VERBOSE = old_verbose
85
98
  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
99
  end
93
100
  end
94
101
  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.3
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
@@ -85,5 +72,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
72
  requirements: []
86
73
  rubygems_version: 4.0.3
87
74
  specification_version: 4
88
- summary: Auto-reload changed Ruby files inside an IRB session.
75
+ summary: Reload changed Ruby files inside an IRB session.
89
76
  test_files: []