irb-reload 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 75727d6f673f08bfae74a3e1568d4d30758221793d983948551618294f3e6fc4
4
+ data.tar.gz: b93b0030ff9d5b14687392f16f9e3502309551e86e3eab6dbe4221373402bc87
5
+ SHA512:
6
+ metadata.gz: '082d664d769a3530fffe97cae10ac9772c9b42413e40a1399c73728ecb53f939a64f0c7aa4353b16b0bae0c4f0624b711c6760347288292007709358918c9b5f'
7
+ data.tar.gz: 1bd28a816a8b52f394a89e6187b90299653847f0732e8741391048c843d4e3df7f20c1dd9c7b4462d594e07a6e267b46d396bf88b534ca5bd168b53708d6b697
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "irb-reload" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["yuuji.yaginuma@gmail.com"](mailto:"yuuji.yaginuma@gmail.com").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Yuji Yaginuma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # IRB::Reload
2
+
3
+ `irb-reload` reloads updated files into IRB session like Rails' `reload` command.
4
+
5
+ ## Installation
6
+
7
+ Add the gem to your application's development dependencies:
8
+
9
+ ```bash
10
+ bundle add irb-reload --group development
11
+ ```
12
+
13
+ Or install it directly:
14
+
15
+ ```bash
16
+ gem install irb-reload
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ 1. Add `require "irb/reload"` to `.irbrc` or `bin/console`.
22
+ 1. Start IRB session
23
+
24
+ ```ruby
25
+ reload! # Reload updated files
26
+ ```
27
+
28
+ ### Configuration
29
+
30
+ You can tweak the watcher through `IRB.conf`.
31
+
32
+ ```ruby
33
+ IRB.conf[:RELOAD] = {
34
+ paths: %w[app lib], # directories to watch. Default is `lib`.
35
+ listen: { latency: 0.2 }, # options forwarded to Listen
36
+ }
37
+ ```
38
+
39
+ Any keys under `:listen` are passed straight to `Listen.to`. Use this to change latency, polling, or ignore patterns.
40
+
41
+ ## Development
42
+
43
+ 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.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/y-yagi/irb-reload. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/y-yagi/irb-reload/blob/main/CODE_OF_CONDUCT.md).
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
54
+
55
+ ## Code of Conduct
56
+
57
+ Everyone interacting in the Irb::Reload project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/y-yagi/irb-reload/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "irb/command"
4
+
5
+ module IRB
6
+ module Reload
7
+ class Command < IRB::Command::Base
8
+ category "reload"
9
+ description "Watch directories and reload updated Ruby files."
10
+ help_message <<~HELP
11
+ Reload updated files.
12
+ HELP
13
+
14
+ def execute(_arg)
15
+ IRB::Reload.reload!
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Reload
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/lib/irb/reload.rb ADDED
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "irb"
4
+ require "listen"
5
+
6
+ require_relative "reload/version"
7
+ require_relative "reload/command"
8
+
9
+ module IRB
10
+ module Reload
11
+ DEFAULT_PATTERN = /\.rb\z/.freeze
12
+ DEFAULT_PATHS = ["lib"]
13
+
14
+ class << self
15
+ def start
16
+ @changed_files = Set.new
17
+ normalized_paths = normalize_paths(config[:paths] || DEFAULT_PATHS)
18
+ listener_options = default_listen_option
19
+
20
+ @listener = Listen.to(*normalized_paths, **listener_options) do |modified, added, _removed|
21
+ record_changed_files(modified, added)
22
+ end
23
+
24
+ @listener.start
25
+ true
26
+ end
27
+
28
+ def reload!
29
+ @changed_files.each do |file|
30
+ reload_file(file)
31
+ end
32
+ @changed_files.clear
33
+ end
34
+
35
+ def watched_paths
36
+ return [] unless @listener
37
+
38
+ @listener.respond_to?(:directories) ? @listener.directories : []
39
+ end
40
+
41
+ def config
42
+ IRB.conf[:RELOAD] ||= {}
43
+ end
44
+
45
+ private
46
+
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
+ def normalize_paths(paths)
55
+ normalized = Array(paths).map(&:to_s).reject(&:empty?)
56
+ normalized = [Dir.pwd] if normalized.empty?
57
+ normalized
58
+ end
59
+
60
+ def record_changed_files(modified, added)
61
+ (Array(modified) + Array(added)).uniq.each do |file|
62
+ next if file.nil?
63
+ next unless ruby_file?(file)
64
+
65
+ record_file(file)
66
+ end
67
+ end
68
+
69
+ def ruby_file?(file)
70
+ File.extname(file) == ".rb"
71
+ end
72
+
73
+ def record_file(file)
74
+ @changed_files.add(file)
75
+ end
76
+
77
+ def reload_file(file)
78
+ old_verbose, $VERBOSE = $VERBOSE, nil
79
+ Kernel.load(file)
80
+ $stdout.puts "[irb-reload] Reloaded #{file}"
81
+ rescue StandardError => e
82
+ warn "[irb-reload] Failed to reload #{file}: #{e.class}: #{e.message}"
83
+ ensure
84
+ $VERBOSE = old_verbose
85
+ 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
+ end
93
+ end
94
+ end
95
+
96
+ IRB::Command.register(:reload!, IRB::Reload::Command)
97
+ IRB::Reload.start
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irb-reload
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuji Yaginuma
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: irb
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.13'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.13'
26
+ - !ruby/object:Gem::Dependency
27
+ name: listen
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.8'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.8'
40
+ email:
41
+ - yuuji.yaginuma@gmail.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - CODE_OF_CONDUCT.md
47
+ - LICENSE.txt
48
+ - README.md
49
+ - Rakefile
50
+ - lib/irb/reload.rb
51
+ - lib/irb/reload/command.rb
52
+ - lib/irb/reload/version.rb
53
+ homepage: https://github.com/y-yagi/irb-reload
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://github.com/y-yagi/irb-reload
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 3.2.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.6.7
73
+ specification_version: 4
74
+ summary: Auto-reload changed Ruby files inside an IRB session.
75
+ test_files: []