require_reloader 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/require_reloader.rb +8 -17
- data/lib/require_reloader/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# RequireReloader
|
2
2
|
|
3
|
-
Auto-reload local gems or `.rb` files that you `require`d
|
3
|
+
Auto-reload local gems or `.rb` files that you `require`'d
|
4
4
|
**without restarting server** in Rails app development.
|
5
5
|
|
6
6
|
Currently, it supports Rails 3+ and above, including 3.1 and 3.2.
|
7
7
|
|
8
8
|
It uses `ActionDispatch::Callbacks.to_prepare` to reload the
|
9
|
-
`require`d files before each request. In Rails 3.2, it uses
|
9
|
+
`require`'d files before each request. In Rails 3.2, it uses
|
10
10
|
`watchable_dirs` to reload only when you modify a file.
|
11
11
|
|
12
12
|
## Usage
|
data/lib/require_reloader.rb
CHANGED
@@ -7,8 +7,6 @@ module RequireReloader
|
|
7
7
|
# Reload all local gems (that is, ones which have a :path attribute)
|
8
8
|
# automatically on each request.
|
9
9
|
#
|
10
|
-
# In Rails 3.2+, reload happens only when a gem is modified.
|
11
|
-
#
|
12
10
|
# To use it, add 'RequireReloader.watch_local_gems!' to
|
13
11
|
# your config/environments/development.rb.
|
14
12
|
#
|
@@ -24,14 +22,14 @@ module RequireReloader
|
|
24
22
|
# Reload a specific gem or a gem-like .rb file
|
25
23
|
# automatically on each request.
|
26
24
|
#
|
27
|
-
# In Rails 3.2+, reload happens only when
|
25
|
+
# In Rails 3.2+, reload happens only when a watchable file is modified.
|
28
26
|
#
|
29
27
|
# To use it, add 'RequireReloader.watch :my_gem' to
|
30
28
|
# your config/environments/development.rb.
|
31
29
|
#
|
32
30
|
def watch(gem_name, opts={})
|
33
31
|
gem = gem_name.to_s
|
34
|
-
watchable_dir =
|
32
|
+
watchable_dir = expanded_gem_path(gem, opts[:path])
|
35
33
|
watchable_exts = opts[:exts] ? Array(opts[:exts]) : [:rb]
|
36
34
|
|
37
35
|
app = Object.const_get(Rails.application.class.parent_name)
|
@@ -41,8 +39,8 @@ module RequireReloader
|
|
41
39
|
config.watchable_dirs[watchable_dir] = watchable_exts
|
42
40
|
end
|
43
41
|
|
44
|
-
#
|
45
|
-
#
|
42
|
+
# based on Tim Cardenas's solution:
|
43
|
+
# http://timcardenas.com/automatically-reload-gems-in-rails-327-on-eve
|
46
44
|
ActionDispatch::Callbacks.to_prepare do
|
47
45
|
klass = gem.classify
|
48
46
|
Object.send(:remove_const, klass) if Object.const_defined?(klass)
|
@@ -54,23 +52,16 @@ module RequireReloader
|
|
54
52
|
|
55
53
|
private
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
def gem_path(gem, preferred_path)
|
55
|
+
def expanded_gem_path(gem, preferred_path)
|
60
56
|
return File.expand_path(preferred_path) if preferred_path
|
61
57
|
local_gem = local_gems.find {|g| g[:name] == gem}
|
62
58
|
local_gem ? File.expand_path(local_gem[:path]) : false
|
63
59
|
end
|
64
60
|
|
65
61
|
def local_gems
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if matches
|
70
|
-
gems << {name: matches[1], path: matches[2]}
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
62
|
+
Bundler.definition.specs.
|
63
|
+
select{|s| s.source.is_a?(Bundler::Source::Path) }.
|
64
|
+
map{|s| {:name => s.name, :path => s.source.path.to_s} }
|
74
65
|
end
|
75
66
|
end
|
76
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: require_reloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-01-
|
13
|
+
date: 2013-01-10 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Auto-reload local gems or .rb files you required in Rails development.
|
16
16
|
email:
|