require_reloader 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +23 -0
- data/README.md +82 -0
- data/Rakefile +2 -0
- data/lib/require_reloader.rb +76 -0
- data/lib/require_reloader/railtie.rb +14 -0
- data/lib/require_reloader/version.rb +3 -0
- data/require_reloader.gemspec +17 -0
- metadata +57 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2013 Huiming Teo
|
2
|
+
Copyright (c) 2012 Colin Young
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# RequireReloader
|
2
|
+
|
3
|
+
Auto-reload local gems or `.rb` files that you `require`d
|
4
|
+
**without restarting server** in Rails app development.
|
5
|
+
|
6
|
+
Currently, it supports Rails 3+ and above, including 3.1 and 3.2.
|
7
|
+
|
8
|
+
It uses `ActionDispatch::Callbacks.to_prepare` to reload the
|
9
|
+
`require`d files before each request. In Rails 3.2, it uses
|
10
|
+
`watchable_dirs` to reload only when you modify a file.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
To reload **all** local gems in `Gemfile` (the ones with `:path`
|
15
|
+
attributes):
|
16
|
+
|
17
|
+
# Gemfile
|
18
|
+
..
|
19
|
+
gem 'my_gem', :path => '~/work/my_gem'
|
20
|
+
gem 'my_gem2', :path => '~/fun/my_gem2'
|
21
|
+
|
22
|
+
|
23
|
+
# config/environments/development.rb
|
24
|
+
YourApp::Application.configure do
|
25
|
+
...
|
26
|
+
RequireReloader.watch_local_gems!
|
27
|
+
end
|
28
|
+
|
29
|
+
To reload a local gem specified in `Gemfile`:
|
30
|
+
|
31
|
+
# config/environments/development.rb
|
32
|
+
YourApp::Application.configure do
|
33
|
+
...
|
34
|
+
RequireReloader.watch :my_gem
|
35
|
+
end
|
36
|
+
|
37
|
+
You can also reload a `.rb` file in `lib` or any directory:
|
38
|
+
|
39
|
+
# config/environments/development.rb
|
40
|
+
YourApp::Application.configure do
|
41
|
+
...
|
42
|
+
RequireReloader.watch :half_baked_gem # in lib/
|
43
|
+
RequireReloader.watch :foo, :path => 'app/models'
|
44
|
+
end
|
45
|
+
|
46
|
+
`:path` option is **optional**. In **Rails 3.2**, `:path` value will be
|
47
|
+
added into `watchable_dirs`. RequireReloader already adds
|
48
|
+
`lib` and `vendor/gems` into `watchable_dirs`. So, you only need to
|
49
|
+
specify `:path` if the file is located in other directory.
|
50
|
+
|
51
|
+
|
52
|
+
## Installation
|
53
|
+
|
54
|
+
Add this line to your application's Gemfile:
|
55
|
+
|
56
|
+
gem 'require_reloader'
|
57
|
+
|
58
|
+
And then execute:
|
59
|
+
|
60
|
+
$ bundle
|
61
|
+
|
62
|
+
Or install it yourself as:
|
63
|
+
|
64
|
+
$ gem install require_reloader
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create new Pull Request
|
73
|
+
|
74
|
+
## Credits
|
75
|
+
|
76
|
+
This gem is forked from Colin Young's [gem_reloader](https://github.com/colinyoung/gem_reloader), based on [a solution by Timothy Cardenas](http://timcardenas.com/automatically-reload-gems-in-rails-327-on-eve), inspired by [a post from Leitch](http://ileitch.github.com/2012/03/24/rails-32-code-reloading-from-lib.html).
|
77
|
+
|
78
|
+
|
79
|
+
## Changelog
|
80
|
+
|
81
|
+
- v0.1.0: Forked colinyoung/gem_reloader, renamed & major rewrite to support Rails 3.2 and new features.
|
82
|
+
- v0.0.2: Added "vendor/gems" to the config.autoload_paths so the user doesn't have to.
|
data/Rakefile
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require "require_reloader/version"
|
2
|
+
require "require_reloader/railtie"
|
3
|
+
|
4
|
+
module RequireReloader
|
5
|
+
class << self
|
6
|
+
|
7
|
+
# Reload all local gems (that is, ones which have a :path attribute)
|
8
|
+
# automatically on each request.
|
9
|
+
#
|
10
|
+
# In Rails 3.2+, reload happens only when a gem is modified.
|
11
|
+
#
|
12
|
+
# To use it, add 'RequireReloader.watch_local_gems!' to
|
13
|
+
# your config/environments/development.rb.
|
14
|
+
#
|
15
|
+
def watch_local_gems!
|
16
|
+
local_gems.each do |gem|
|
17
|
+
watch gem[:name], :path => gem[:path]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Propose to deprecate :watch_all! and reserve it for future usage.
|
22
|
+
alias_method :watch_all!, :watch_local_gems!
|
23
|
+
|
24
|
+
# Reload a specific gem or a gem-like .rb file
|
25
|
+
# automatically on each request.
|
26
|
+
#
|
27
|
+
# In Rails 3.2+, reload happens only when the gem is modified.
|
28
|
+
#
|
29
|
+
# To use it, add 'RequireReloader.watch :my_gem' to
|
30
|
+
# your config/environments/development.rb.
|
31
|
+
#
|
32
|
+
def watch(gem_name, opts={})
|
33
|
+
gem = gem_name.to_s
|
34
|
+
watchable_dir = gem_path(gem, opts[:path])
|
35
|
+
watchable_exts = opts[:exts] ? Array(opts[:exts]) : [:rb]
|
36
|
+
|
37
|
+
app = Object.const_get(Rails.application.class.parent_name)
|
38
|
+
app::Application.configure do
|
39
|
+
|
40
|
+
if watchable_dir && config.respond_to?(:watchable_dirs)
|
41
|
+
config.watchable_dirs[watchable_dir] = watchable_exts
|
42
|
+
end
|
43
|
+
|
44
|
+
# This code (slightly modified) comes almost entirely from
|
45
|
+
# Tim Cardenas - http://timcardenas.com/automatically-reload-gems-in-rails-327-on-eve
|
46
|
+
ActionDispatch::Callbacks.to_prepare do
|
47
|
+
klass = gem.classify
|
48
|
+
Object.send(:remove_const, klass) if Object.const_defined?(klass)
|
49
|
+
$".delete_if {|s| s.include?(gem)}
|
50
|
+
require gem
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
PATH_REGEX = /gem[^'"]*['"]([^'"]+)['"].*path[^'"]+['"]([^'"]+)['"]/
|
58
|
+
|
59
|
+
def gem_path(gem, preferred_path)
|
60
|
+
return File.expand_path(preferred_path) if preferred_path
|
61
|
+
local_gem = local_gems.find {|g| g[:name] == gem}
|
62
|
+
local_gem ? File.expand_path(local_gem[:path]) : false
|
63
|
+
end
|
64
|
+
|
65
|
+
def local_gems
|
66
|
+
Array.new.tap do |gems|
|
67
|
+
File.open(Rails.root.join('Gemfile'), 'rb').each do |ln|
|
68
|
+
matches = ln.match(PATH_REGEX)
|
69
|
+
if matches
|
70
|
+
gems << {name: matches[1], path: matches[2]}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class RequireReloaderRailtie < Rails::Railtie
|
2
|
+
|
3
|
+
initializer 'require_reloader.autoload', :before => :set_autoload_paths do |app|
|
4
|
+
app.config.autoload_paths += Dir["#{app.config.root}/vendor/gems/"]
|
5
|
+
end
|
6
|
+
|
7
|
+
initializer 'require_reloader.add_watchable_dirs', :before => :set_autoload_paths do |app|
|
8
|
+
if app.config.respond_to?(:watchable_dirs)
|
9
|
+
app.config.watchable_dirs['vendor/gems'] = [:rb]
|
10
|
+
app.config.watchable_dirs['lib'] = [:rb]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/require_reloader/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Colin Young", "Huiming Teo"]
|
6
|
+
gem.email = ["me@colinyoung.com", "teohuiming@gmail.com"]
|
7
|
+
gem.description = %q{Auto-reload local gems or .rb files you required in Rails development.}
|
8
|
+
gem.summary = %q{Auto-reload local gems or .rb files that you required without restarting server during Rails app development.}
|
9
|
+
gem.homepage = "https://github.com/teohm/require_reloader"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "require_reloader"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = RequireReloader::VERSION
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: require_reloader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Colin Young
|
9
|
+
- Huiming Teo
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Auto-reload local gems or .rb files you required in Rails development.
|
16
|
+
email:
|
17
|
+
- me@colinyoung.com
|
18
|
+
- teohuiming@gmail.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/require_reloader.rb
|
29
|
+
- lib/require_reloader/railtie.rb
|
30
|
+
- lib/require_reloader/version.rb
|
31
|
+
- require_reloader.gemspec
|
32
|
+
homepage: https://github.com/teohm/require_reloader
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.23
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Auto-reload local gems or .rb files that you required without restarting
|
56
|
+
server during Rails app development.
|
57
|
+
test_files: []
|