irb_reload 0.0.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/irb_reload.gemspec +23 -0
- data/lib/irb_reload.rb +10 -0
- data/lib/irb_reload/reloader.rb +97 -0
- data/lib/irb_reload/version.rb +3 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dan Olson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# IrbReload
|
2
|
+
|
3
|
+
IrbReload is a lightweight library for reloading code in an IRB session.
|
4
|
+
It's a great tool for gem authors while a gem is under active development.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
# most likely in a :development group
|
12
|
+
group :development do
|
13
|
+
gem 'irb_reload'
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install irb_reload
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
After [installing](#installation), add the following this line to your ~/.irbrc file:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'irb_reload'
|
31
|
+
```
|
32
|
+
|
33
|
+
Or, if you prefer, simply require 'irb_reload' when you start an IRB session.
|
34
|
+
|
35
|
+
Assuming your IRB session was started in the root directory of your project, IrbReload will find
|
36
|
+
and reload all your project's classes and constants, even under multiple namespaces.
|
37
|
+
|
38
|
+
Just like Rails console, just type:
|
39
|
+
|
40
|
+
`reload!`
|
41
|
+
|
42
|
+
and you're good to go!
|
43
|
+
|
44
|
+
## Interpreter Compatibility
|
45
|
+
|
46
|
+
IrbReload is compatible with MRI 1.9 and 2.0 and has been tested on JRuby 1.7.3
|
47
|
+
|
48
|
+
## Caveats
|
49
|
+
|
50
|
+
* IrbReload expects you to start your IRB session in the root of your project.
|
51
|
+
* Due to the above, It probably won't work if you change the cwd of your Ruby process, i.e. `Dir.chdir 'lib/'`
|
52
|
+
* IrbReload assumes you're following basic Ruby conventions regarding your directory structure. see [this link](http://guides.rubygems.org/make-your-own-gem/)
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/irb_reload.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'irb_reload/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "irb_reload"
|
8
|
+
spec.version = IrbReload::VERSION
|
9
|
+
spec.authors = ["Dan Olson"]
|
10
|
+
spec.email = ["daniel.olson@code42.com"]
|
11
|
+
spec.description = %q{A small library for code reloading in your IRB session.}
|
12
|
+
spec.summary = %q{A small library for code reloading in your IRB session.}
|
13
|
+
spec.homepage = "https://github.com/code42/irb_reload"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/irb_reload.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
module IrbReload
|
2
|
+
class Reloader
|
3
|
+
|
4
|
+
def reload!
|
5
|
+
clear_constants
|
6
|
+
remove_project_namespace
|
7
|
+
unrequire_lib_files
|
8
|
+
reload_project_file
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def clear_constants(namespace=project_namespace, const_array=[])
|
14
|
+
const_array.unshift(project_namespace.to_s) unless const_array[0] == project_namespace.to_s
|
15
|
+
namespace.constants(false).each do |const|
|
16
|
+
new_const_array = (const_array + [const.to_s])
|
17
|
+
klass = new_const_array.inject(Module){ |m, name| m.const_get(name) }
|
18
|
+
case klass
|
19
|
+
when Module; clear_constants klass, new_const_array
|
20
|
+
when Class; remove_klass_constants klass
|
21
|
+
else; namespace.send :remove_const, const
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove_project_namespace
|
27
|
+
Object.send :remove_const, project_namespace.name.to_sym
|
28
|
+
end
|
29
|
+
|
30
|
+
# Make Ruby forget it required the project files; we can rely
|
31
|
+
# on the project to require them again.
|
32
|
+
def unrequire_lib_files
|
33
|
+
$LOADED_FEATURES.reject! { |file| file.start_with? project_dir }
|
34
|
+
end
|
35
|
+
|
36
|
+
def reload_project_file
|
37
|
+
load File.join lib_dir, project_file_name
|
38
|
+
end
|
39
|
+
|
40
|
+
def lib_files
|
41
|
+
@lib_files ||= Dir.entries(project_dir).select { |e| File.file? File.join(project_dir, e) }
|
42
|
+
end
|
43
|
+
|
44
|
+
# Used for comparing constant names and filenames
|
45
|
+
def smush_name(string)
|
46
|
+
string.split('.').first.gsub('_', '').downcase
|
47
|
+
end
|
48
|
+
|
49
|
+
# Assumes we're at the root of the project
|
50
|
+
def lib_dir
|
51
|
+
File.join Dir.pwd, 'lib'
|
52
|
+
end
|
53
|
+
|
54
|
+
def project_dir
|
55
|
+
File.join lib_dir, project_dir_name
|
56
|
+
end
|
57
|
+
|
58
|
+
def project_dir_name
|
59
|
+
@project_dir_name ||= Dir.entries(lib_dir).find do |f|
|
60
|
+
project_file_name.start_with?(f) && File.directory?(File.join(lib_dir, f))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def project_file_name
|
65
|
+
@project_file_name ||= Dir.entries(lib_dir).find { |f| f.end_with? '.rb' }
|
66
|
+
end
|
67
|
+
|
68
|
+
def project_namespace
|
69
|
+
Module.const_get get_project_namespace
|
70
|
+
end
|
71
|
+
|
72
|
+
def remove_klass_constants(klass)
|
73
|
+
klass.constants(false).each do |const|
|
74
|
+
klass.send :remove_const, const
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# First try to infer the namespace from the contents of the project
|
79
|
+
# file. If we can't, infer it from the project file's name.
|
80
|
+
def get_project_namespace
|
81
|
+
parse_file_for_namespace || namespace_from_file_name
|
82
|
+
end
|
83
|
+
|
84
|
+
def parse_file_for_namespace
|
85
|
+
IO.popen("cat #{File.join(lib_dir, project_file_name)}") do |cat|
|
86
|
+
loop do
|
87
|
+
break nil if cat.eof?
|
88
|
+
break $1 if cat.gets =~ /module\s+(\S+)/
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def namespace_from_file_name
|
94
|
+
File.basename(project_file_name, '.rb').split('_').map(&:capitalize).join
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: irb_reload
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Olson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A small library for code reloading in your IRB session.
|
47
|
+
email:
|
48
|
+
- daniel.olson@code42.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- irb_reload.gemspec
|
59
|
+
- lib/irb_reload.rb
|
60
|
+
- lib/irb_reload/reloader.rb
|
61
|
+
- lib/irb_reload/version.rb
|
62
|
+
homepage: https://github.com/code42/irb_reload
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.24
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: A small library for code reloading in your IRB session.
|
87
|
+
test_files: []
|