require_reloader 0.1.0 → 0.1.1

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 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
@@ -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 the gem is modified.
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 = gem_path(gem, opts[:path])
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
- # This code (slightly modified) comes almost entirely from
45
- # Tim Cardenas - http://timcardenas.com/automatically-reload-gems-in-rails-327-on-eve
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
- PATH_REGEX = /gem[^'"]*['"]([^'"]+)['"].*path[^'"]+['"]([^'"]+)['"]/
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
- 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
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
@@ -1,3 +1,3 @@
1
1
  module RequireReloader
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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.0
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-09 00:00:00.000000000 Z
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: