irb-reload 0.1.3 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +14 -1
- data/lib/irb/reload/context_extension.rb +14 -0
- data/lib/irb/reload/version.rb +1 -1
- data/lib/irb/reload.rb +37 -20
- metadata +5 -4
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 297149a346645065f70ccf431f6a1e7216205871b3e2ea09df30d9ebb8c80480
|
|
4
|
+
data.tar.gz: d7e10f79f5cf45717f7f34f58f6d4974d04b1a586d8deac5b5717d5ab5d2b006
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d5a8dc65f4a31fe0c417bc57c1395cae869f302ba3fbcb23f2707d7ba597398265506a103b4c8af12afb67c9b336baf4f7a1df1aaae5892be9367cf121de48bd
|
|
7
|
+
data.tar.gz: 31ba3cacbbe3d2f27370302dae8d72fa8f576f8b7ad9f0edb837bf677367d62b9ad4fe96f5afa42497dc21fb079fd7df5b4651b40ab3eca98c4762b868d37219
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
|
@@ -25,13 +25,26 @@ gem install irb-reload
|
|
|
25
25
|
reload! # Reload updated files
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
### Auto reload
|
|
29
|
+
|
|
30
|
+
Set `auto` to reload updated files without typing `reload!`.
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
IRB.conf[:RELOAD] = {
|
|
34
|
+
auto: true,
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Files are reloaded just before IRB evaluates your next input, not the moment you save them.
|
|
39
|
+
|
|
28
40
|
### Configuration
|
|
29
41
|
|
|
30
42
|
You can tweak the watcher through `IRB.conf`.
|
|
31
43
|
|
|
32
44
|
```ruby
|
|
33
45
|
IRB.conf[:RELOAD] = {
|
|
34
|
-
|
|
46
|
+
paths: %w[app lib], # directories to watch. Default is `lib`.
|
|
47
|
+
auto: true, # reload updated files automatically. Default is `false`.
|
|
35
48
|
}
|
|
36
49
|
```
|
|
37
50
|
|
data/lib/irb/reload/version.rb
CHANGED
data/lib/irb/reload.rb
CHANGED
|
@@ -6,22 +6,24 @@ require "watchcat"
|
|
|
6
6
|
|
|
7
7
|
require_relative "reload/version"
|
|
8
8
|
require_relative "reload/command"
|
|
9
|
+
require_relative "reload/context_extension"
|
|
9
10
|
|
|
10
11
|
module IRB
|
|
11
12
|
module Reload
|
|
12
13
|
DEFAULT_PATHS = ["lib"]
|
|
13
|
-
|
|
14
|
-
ignore_remove: true,
|
|
15
|
-
|
|
14
|
+
WATCHCAT_OPTIONS = {
|
|
15
|
+
filters: { ignore_remove: true,ignore_access: true },
|
|
16
|
+
patterns: [ "*.rb" ],
|
|
16
17
|
}.freeze
|
|
17
18
|
|
|
18
19
|
class << self
|
|
19
20
|
def start
|
|
21
|
+
@mutex = Mutex.new
|
|
20
22
|
@changed_files = Set.new
|
|
21
23
|
normalized_paths = normalize_paths(config[:paths] || DEFAULT_PATHS)
|
|
22
24
|
|
|
23
25
|
@watcher&.stop if defined?(@watcher) && @watcher
|
|
24
|
-
@watcher = Watchcat.watch(normalized_paths,
|
|
26
|
+
@watcher = Watchcat.watch(normalized_paths, **WATCHCAT_OPTIONS) do |event|
|
|
25
27
|
record_watchcat_event(event)
|
|
26
28
|
end
|
|
27
29
|
|
|
@@ -29,11 +31,18 @@ module IRB
|
|
|
29
31
|
true
|
|
30
32
|
end
|
|
31
33
|
|
|
32
|
-
def reload!
|
|
33
|
-
|
|
34
|
-
reload_file(file)
|
|
34
|
+
def reload!(verbose: true)
|
|
35
|
+
consume_changed_files.each do |file|
|
|
36
|
+
reload_file(file, verbose:)
|
|
35
37
|
end
|
|
36
|
-
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def auto?
|
|
41
|
+
config[:auto] == true
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def auto_reload!
|
|
45
|
+
reload!(verbose: false) if auto?
|
|
37
46
|
end
|
|
38
47
|
|
|
39
48
|
def watched_paths
|
|
@@ -54,10 +63,7 @@ module IRB
|
|
|
54
63
|
|
|
55
64
|
def record_changed_files(modified, added)
|
|
56
65
|
(Array(modified) + Array(added)).uniq.each do |file|
|
|
57
|
-
|
|
58
|
-
next unless ruby_file?(file)
|
|
59
|
-
|
|
60
|
-
record_file(file)
|
|
66
|
+
record_file(file) unless file.nil?
|
|
61
67
|
end
|
|
62
68
|
end
|
|
63
69
|
|
|
@@ -79,20 +85,30 @@ module IRB
|
|
|
79
85
|
kind.create? || kind.modify? || kind.any?
|
|
80
86
|
end
|
|
81
87
|
|
|
82
|
-
def
|
|
83
|
-
|
|
88
|
+
def record_file(file)
|
|
89
|
+
@mutex.synchronize { @changed_files.add(file) }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def consume_changed_files
|
|
93
|
+
@mutex.synchronize do
|
|
94
|
+
pending = @changed_files.to_a
|
|
95
|
+
@changed_files.clear
|
|
96
|
+
pending
|
|
97
|
+
end
|
|
84
98
|
end
|
|
85
99
|
|
|
86
|
-
def
|
|
87
|
-
|
|
100
|
+
def reload_file(file, verbose: true)
|
|
101
|
+
load_quietly(file)
|
|
102
|
+
$stdout.puts "[irb-reload] Reloaded #{file}" if verbose
|
|
103
|
+
rescue LoadError
|
|
104
|
+
# The file was removed or moved. Nothing to reload.
|
|
105
|
+
rescue ScriptError, StandardError => e
|
|
106
|
+
warn "[irb-reload] Failed to reload #{file}: #{e.class}: #{e.message}"
|
|
88
107
|
end
|
|
89
108
|
|
|
90
|
-
def
|
|
109
|
+
def load_quietly(file)
|
|
91
110
|
old_verbose, $VERBOSE = $VERBOSE, nil
|
|
92
111
|
Kernel.load(file)
|
|
93
|
-
$stdout.puts "[irb-reload] Reloaded #{file}"
|
|
94
|
-
rescue StandardError => e
|
|
95
|
-
warn "[irb-reload] Failed to reload #{file}: #{e.class}: #{e.message}"
|
|
96
112
|
ensure
|
|
97
113
|
$VERBOSE = old_verbose
|
|
98
114
|
end
|
|
@@ -101,4 +117,5 @@ module IRB
|
|
|
101
117
|
end
|
|
102
118
|
|
|
103
119
|
IRB::Command.register(:reload!, IRB::Reload::Command)
|
|
120
|
+
IRB::Context.prepend(IRB::Reload::ContextExtension)
|
|
104
121
|
IRB::Reload.start
|
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.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yuji Yaginuma
|
|
@@ -29,27 +29,28 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0.
|
|
32
|
+
version: '0.6'
|
|
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: '0.
|
|
39
|
+
version: '0.6'
|
|
40
40
|
email:
|
|
41
41
|
- yuuji.yaginuma@gmail.com
|
|
42
42
|
executables: []
|
|
43
43
|
extensions: []
|
|
44
44
|
extra_rdoc_files: []
|
|
45
45
|
files:
|
|
46
|
-
-
|
|
46
|
+
- CHANGELOG.md
|
|
47
47
|
- CODE_OF_CONDUCT.md
|
|
48
48
|
- LICENSE.txt
|
|
49
49
|
- README.md
|
|
50
50
|
- Rakefile
|
|
51
51
|
- lib/irb/reload.rb
|
|
52
52
|
- lib/irb/reload/command.rb
|
|
53
|
+
- lib/irb/reload/context_extension.rb
|
|
53
54
|
- lib/irb/reload/version.rb
|
|
54
55
|
homepage: https://github.com/y-yagi/irb-reload
|
|
55
56
|
licenses:
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
4.0.1
|