gem_reloader 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gem_reloader.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Colin Young
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,39 @@
1
+ # GemReloader
2
+
3
+ Stop restarting your server after editing local gems!
4
+
5
+ ## Usage
6
+
7
+ In your `development.rb`, add:
8
+
9
+ GemReloader.watch :my_gem
10
+
11
+ Or, if you want to watch **all** local gems:
12
+
13
+ GemReloader.watch_all!
14
+
15
+ That's literally it. Tiny but useful.
16
+
17
+ By the way, a gem will be picked up by `::watch_all!` if it has a :path attribute.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'gem_reloader'
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install gem_reloader
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/gem_reloader/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Colin Young"]
6
+ gem.email = ["me@colinyoung.com"]
7
+ gem.description = %q{Stop restarting your server after editing local gems}
8
+ gem.summary = %q{With GemReloader, watch local gems just like you do your models and controllers.}
9
+ gem.homepage = "https://github.com/colinyoung/gem_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 = "gem_reloader"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = GemReloader::VERSION
17
+ end
@@ -0,0 +1,3 @@
1
+ module GemReloader
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,64 @@
1
+ require "gem_reloader/version"
2
+
3
+ module GemReloader
4
+
5
+ # All local gems (that is, ones which have a :path attribute)
6
+ # will be automatically reloaded on each request.
7
+ #
8
+ # Add something like 'GemReloader.watch_all!' to your development.rb.
9
+ def self.watch_all!
10
+ reloadable_gems.each do |gem|
11
+ watch gem[:name]
12
+ end
13
+ end
14
+
15
+ # Watch a specific gem.
16
+ # Add something like 'GemReloader.watch :my_gem' to your development.rb.
17
+ def self.watch(gem_symbol)
18
+
19
+ gem_path = gem_symbol.to_s
20
+ klass = gem_path.classify
21
+
22
+ app = Object.const_get(Rails.application.class.parent_name)
23
+ app::Application.configure do
24
+
25
+ ActionDispatch::Callbacks.to_prepare do
26
+
27
+ # This code (slightly modified) comes almost entirely from
28
+ # Tim Cardenas - http://timcardenas.com/automatically-reload-gems-in-rails-327-on-eve
29
+
30
+ # If the gem's top level module is currently loaded, unload it
31
+ if Object.const_defined?(klass)
32
+ Object.send(:remove_const, klass)
33
+ end
34
+
35
+ # Instruct ruby to "unrequire" all of the gems files.
36
+ # CAREFUL: make sure this only matches your gems files.
37
+ $".delete_if {|s| s.include?(gem_path)}
38
+
39
+ # Re-require your gem
40
+ # Note: because we removed all files previously required they will be reloaded
41
+ # even if you didn't use load/autoload in your gem.
42
+ require gem_path
43
+
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ PATH_REGEX = /^gem[\(| ]['"](\w+)['"][|,](?:.*)path[ =>\:]+['"]([\w\/]+)['"]/
52
+
53
+ def self.reloadable_gems
54
+ Array.new.tap do |gems|
55
+ File.open(Rails.root.join('Gemfile'), 'rb').each do |ln|
56
+ matches = ln.match(PATH_REGEX)
57
+ if matches
58
+ gems << {name: matches[1], path: matches[2]}
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_reloader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Colin Young
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Stop restarting your server after editing local gems
15
+ email:
16
+ - me@colinyoung.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - gem_reloader.gemspec
27
+ - lib/gem_reloader.rb
28
+ - lib/gem_reloader/version.rb
29
+ homepage: https://github.com/colinyoung/gem_reloader
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: With GemReloader, watch local gems just like you do your models and controllers.
53
+ test_files: []
54
+ has_rdoc: