require_reloader 0.1.4 → 0.1.5
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/README.md +2 -0
- data/lib/require_reloader.rb +5 -2
- data/lib/require_reloader/helper.rb +80 -0
- data/lib/require_reloader/version.rb +1 -1
- data/require_reloader.gemspec +2 -0
- metadata +20 -3
data/README.md
CHANGED
@@ -69,6 +69,8 @@ This gem is forked from Colin Young's [gem_reloader](https://github.com/colinyou
|
|
69
69
|
|
70
70
|
## Changelog
|
71
71
|
|
72
|
+
- v0.1.5: properly guess top-level module name based on gem name
|
73
|
+
pattern, only watch git repo if it's local.
|
72
74
|
- v0.1.4: remove 'vendor/gems' from watchable_dirs & autoload_paths, as local gem path is already specified in Gemfile.
|
73
75
|
- v0.1.3: Skip reload local gem if it's itself; added integration tests.
|
74
76
|
- v0.1.2: Minor rephrase on gem's description and summary.
|
data/lib/require_reloader.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "require_reloader/version"
|
2
2
|
require "require_reloader/railtie"
|
3
|
+
require "require_reloader/helper"
|
3
4
|
|
4
5
|
module RequireReloader
|
5
6
|
class << self
|
@@ -34,6 +35,7 @@ module RequireReloader
|
|
34
35
|
gem = gem_name.to_s
|
35
36
|
watchable_dir = expanded_gem_path(gem, opts[:path])
|
36
37
|
watchable_exts = opts[:exts] ? Array(opts[:exts]) : [:rb]
|
38
|
+
helper = Helper.new
|
37
39
|
|
38
40
|
app = Object.const_get(Rails.application.class.parent_name)
|
39
41
|
app::Application.configure do
|
@@ -45,8 +47,7 @@ module RequireReloader
|
|
45
47
|
# based on Tim Cardenas's solution:
|
46
48
|
# http://timcardenas.com/automatically-reload-gems-in-rails-327-on-eve
|
47
49
|
ActionDispatch::Callbacks.to_prepare do
|
48
|
-
|
49
|
-
Object.send(:remove_const, klass) if Object.const_defined?(klass)
|
50
|
+
helper.remove_module_if_defined(gem)
|
50
51
|
$".delete_if {|s| s.include?(gem)}
|
51
52
|
require gem
|
52
53
|
end
|
@@ -61,9 +62,11 @@ module RequireReloader
|
|
61
62
|
local_gem ? File.expand_path(local_gem[:path]) : false
|
62
63
|
end
|
63
64
|
|
65
|
+
# returns only local gems, local git repo
|
64
66
|
def local_gems
|
65
67
|
Bundler.definition.specs.
|
66
68
|
select{|s| s.source.is_a?(Bundler::Source::Path) }.
|
69
|
+
delete_if{|s| s.source.is_a?(Bundler::Source::Git) && !s.source.send(:local?) }.
|
67
70
|
map{|s| {:name => s.name, :path => s.source.path.to_s} }
|
68
71
|
end
|
69
72
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module RequireReloader
|
2
|
+
# Methods copied from latest ActiveSupport::Inflector to support
|
3
|
+
# older Rails versions (e.g. 3.0) without these methods.
|
4
|
+
module ActionPackInfectorMethods
|
5
|
+
def deconstantize(path)
|
6
|
+
path.to_s[0...(path.rindex('::') || 0)] # implementation based on the one in facets' Module#spacename
|
7
|
+
end
|
8
|
+
|
9
|
+
def constantize(camel_cased_word)
|
10
|
+
names = camel_cased_word.split('::')
|
11
|
+
names.shift if names.empty? || names.first.empty?
|
12
|
+
|
13
|
+
constant = Object
|
14
|
+
names.each do |name|
|
15
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
16
|
+
end
|
17
|
+
constant
|
18
|
+
end
|
19
|
+
|
20
|
+
def const_regexp(camel_cased_word) #:nodoc:
|
21
|
+
parts = camel_cased_word.split("::")
|
22
|
+
last = parts.pop
|
23
|
+
|
24
|
+
parts.reverse.inject(last) do |acc, part|
|
25
|
+
part.empty? ? acc : "#{part}(::#{acc})?"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def demodulize(path)
|
30
|
+
path = path.to_s
|
31
|
+
if i = path.rindex('::')
|
32
|
+
path[(i+2)..-1]
|
33
|
+
else
|
34
|
+
path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def safe_constantize(camel_cased_word)
|
39
|
+
begin
|
40
|
+
constantize(camel_cased_word)
|
41
|
+
rescue NameError => e
|
42
|
+
raise unless e.message =~ /(uninitialized constant|wrong constant name) #{const_regexp(camel_cased_word)}$/ ||
|
43
|
+
e.name.to_s == camel_cased_word.to_s
|
44
|
+
rescue ArgumentError => e
|
45
|
+
raise unless e.message =~ /not missing constant #{const_regexp(camel_cased_word)}\!$/
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Helper
|
51
|
+
include ActionPackInfectorMethods
|
52
|
+
|
53
|
+
def remove_module_if_defined(gem_name)
|
54
|
+
full_name = full_qualified_name(gem_name)
|
55
|
+
remove_module(full_name) if module_defined?(full_name)
|
56
|
+
end
|
57
|
+
|
58
|
+
def module_defined?(full_name)
|
59
|
+
!!safe_constantize(full_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
def remove_module(full_name)
|
63
|
+
module_namespace = deconstantize(full_name)
|
64
|
+
module_name = demodulize(full_name)
|
65
|
+
parent_module = module_namespace == "" ? Object : constantize(module_namespace)
|
66
|
+
parent_module.send(:remove_const, module_name)
|
67
|
+
end
|
68
|
+
|
69
|
+
def full_qualified_name(gem_name)
|
70
|
+
return nil unless gem_name
|
71
|
+
gem_name.split("-").map{|token| camelcase(token)}.join("::")
|
72
|
+
end
|
73
|
+
|
74
|
+
def camelcase(str)
|
75
|
+
str.split("_").map{|token| token.capitalize }.join("")
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/require_reloader.gemspec
CHANGED
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,8 +10,24 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-01-
|
14
|
-
dependencies:
|
13
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: minitest
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
15
31
|
description: Auto-reload require files or local gems without restarting server during
|
16
32
|
Rails development.
|
17
33
|
email:
|
@@ -27,6 +43,7 @@ files:
|
|
27
43
|
- README.md
|
28
44
|
- Rakefile
|
29
45
|
- lib/require_reloader.rb
|
46
|
+
- lib/require_reloader/helper.rb
|
30
47
|
- lib/require_reloader/railtie.rb
|
31
48
|
- lib/require_reloader/version.rb
|
32
49
|
- require_reloader.gemspec
|