mr-sparkle 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.3.0
2
+
3
+ * In addition to gems in the :default group, also preload gems in the group specified in the RACK\_ENV environment variable, or :development if RACK\_ENV is unset. This is similar to Rails behavior. (Jonathan Davies)
4
+
1
5
  ### 0.2.0
2
6
 
3
7
  * Allow polling to be forced on with --force-polling. If you have mounted the files over NFS, and are editing them remotely, then file system events are not fired, so the reloading doesn't work. Force it to poll with --force-polling and it will work in this case. (Jamie Cobbett)
data/README.md CHANGED
@@ -7,7 +7,7 @@ This gem contains a script to start a [Unicorn](http://unicorn.bogomips.org/)-ba
7
7
  The main purpose of this gem is to take Jonathan's idea and package it into something can "just work" without having to be customized inside each project's code. Besides the gem packaging, this code differs from the original watcher script in the following ways:
8
8
 
9
9
  1. It uses [listen](https://github.com/guard/listen) instead of [directory_watcher](https://github.com/TwP/directory_watcher/), which provides native event-driven file change detection, instead of polling.
10
- 1. It assumes you're using [Bundler](http://gembundler.com/) for dependencies, which means that instead of needing a hardcoded list of gems in the `before_fork` hook, like the blog post had, this plugin just does `Bundler.require(:default)` to get all the modules mentioned in the Gemfile loaded before forking.
10
+ 1. It assumes you're using [Bundler](http://gembundler.com/) for dependencies, which means that instead of needing a hardcoded list of gems in the `before_fork` hook, like the blog post had, this plugin just does `Bundler.require(:default, ENV['RACK_ENV'])` to get all the modules mentioned in the Gemfile loaded before forking. (Unicorn will default the RACK_ENV variable to development if it isn't set already, so by default you'll get all the gems in the `:default` and `:development` groups.)
11
11
  1. If you change your Gemfile, the preloads are no longer valid, so this script treats that change as a special case: when the Gemfile changes, we kill the whole server and restart it, thus reloading absolutely everything.
12
12
 
13
13
  The script comes with a default set of file extensions it will watch for changes. I've tried to be liberal about it--no harm reloading a few extra times when developing. You can run `mr-sparkle --help` to see the default set as a regexp, and you can change that regexp with the `--pattern` option.
@@ -38,7 +38,7 @@ Any arguments after the `--` will be passed on to unicorn. This is how you woul
38
38
 
39
39
  ## Requirements
40
40
 
41
- This script requires Ruby 1.9.1 or greater (because it depends on `Kernel.spawn`.) Since it's a wrapper around Unicorn, it will only work on "unix or unix-like" systems where unicorn is supported.
41
+ This script requires Ruby 1.9.3 or greater. Since it's a wrapper around Unicorn, it will only work on "unix or unix-like" systems where unicorn is supported.
42
42
 
43
43
  ## Contributing
44
44
 
@@ -4,5 +4,5 @@ GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true
4
4
 
5
5
  before_fork do |server, worker|
6
6
  require 'bundler'
7
- Bundler.require(:default)
7
+ Bundler.require(:default, ENV["RACK_ENV"])
8
8
  end
@@ -1,5 +1,5 @@
1
1
  module Mr
2
2
  module Sparkle
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -11,7 +11,8 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{This gem contains a script to start a Unicorn-based server for your Rack application that reloads your automatically when they are changed, but doesn't incur the penalty of reloading all the gem dependencies. It's based on Jonathan D. Stott's blog post "Magical Reloading Sparkles"--hence the name.}
12
12
  gem.summary = %q{Runs Unicorn, automatically reloading the application, but not bundled gems.}
13
13
  gem.homepage = "http://github.com/MicahChalmer/mr-sparkle"
14
- gem.required_ruby_version = '>= 1.9.1'
14
+ gem.license = 'MIT'
15
+ gem.required_ruby_version = '>= 1.9.3'
15
16
 
16
17
  gem.files = `git ls-files`.split($/)
17
18
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -0,0 +1,12 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gem 'rack', '>= 1.4'
5
+
6
+ group :development do
7
+ gem 'my_development_gem', :path=>'vendor/my_development_gem'
8
+ end
9
+
10
+ group :foo do
11
+ gem 'my_foo_gem', :path=>'vendor/my_foo_gem'
12
+ end
@@ -0,0 +1,2 @@
1
+ puts "HEY my rack_env is #{ENV['RACK_ENV']}"
2
+ run lambda {|env| [200, {'Content-Type' => 'text/plain; charset=utf8'}, [($gems_loaded || []).join(",")]] }
@@ -0,0 +1,4 @@
1
+ module MyDevelopmentGem
2
+ $gems_loaded ||= []
3
+ $gems_loaded << "development"
4
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "my_development_gem"
7
+ gem.version = '0.0.1'
8
+ gem.authors = ["Micah Chalmer"]
9
+ gem.email = ["micah@micahchalmer.net"]
10
+ gem.description = %q{This is only here as part of a test fixture}
11
+ gem.summary = %q{This is only here as part of a test fixture}
12
+ gem.homepage = ""
13
+
14
+ gem.files = ['lib/my_development_gem.rb']
15
+ gem.executables = []
16
+ gem.test_files = []
17
+ gem.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,4 @@
1
+ module MyFooGem
2
+ $gems_loaded ||= []
3
+ $gems_loaded << "foo"
4
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "my_foo_gem"
7
+ gem.version = '0.0.1'
8
+ gem.authors = ["Micah Chalmer"]
9
+ gem.email = ["micah@micahchalmer.net"]
10
+ gem.description = %q{This is only here as part of a test fixture}
11
+ gem.summary = %q{This is only here as part of a test fixture}
12
+ gem.homepage = ""
13
+
14
+ gem.files = ['lib/my_foo_gem.rb']
15
+ gem.executables = []
16
+ gem.test_files = []
17
+ gem.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe "App Runner: Loading bundler groups based on RACK_ENV" do
4
+ before do
5
+ self.app_template_path = app_template_fixture("load_rack_env_group")
6
+ end
7
+
8
+ it "loads the group whose name is specified by RACK_ENV" do
9
+ start_app({'RACK_ENV'=>'foo'})
10
+ app_request('/').body.must_equal('foo')
11
+ end
12
+
13
+ it "loads the development group if specified" do
14
+ start_app({'RACK_ENV'=>'development'})
15
+ app_request('/').body.must_equal('development')
16
+ end
17
+
18
+ it "loads no groups if nothing is specified" do
19
+ start_app({'RACK_ENV'=>''})
20
+ app_request('/').body.must_equal('')
21
+ end
22
+
23
+ it "loads the development group if RACK_ENV is unset" do
24
+ start_app({'RACK_ENV'=>nil})
25
+ app_request('/').body.must_equal('development')
26
+ end
27
+ end
@@ -37,13 +37,14 @@ class ServerAppTest < MiniTest::Spec
37
37
  @app_args || []
38
38
  end
39
39
 
40
- def start_app
40
+ def start_app(env_vars={})
41
41
  stop_app
42
42
  @app_socket_path = File.expand_path("main_unicorn_socket", running_app_dir)
43
43
  Dir.mkdir(File.expand_path('log', running_app_dir))
44
44
  @app_stdout, app_stdout_w = IO.pipe
45
45
  @app_stderr, app_stderr_w = IO.pipe
46
46
  Bundler.with_clean_env do
47
+ ENV.replace(Hash[ENV.to_a].merge(env_vars))
47
48
  # Need to generate the right Gemfile.lock so that we don't generate it
48
49
  # from the app itself, creating spurious reload events
49
50
  unless File.exists?(File.expand_path('Gemfile.lock', running_app_dir))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mr-sparkle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2013-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: unicorn
@@ -185,11 +185,19 @@ files:
185
185
  - spec/fixtures/full_reload/vendor/full_reload_test_gem/lib/full_reload_test_gem.rb
186
186
  - spec/fixtures/hello/Gemfile
187
187
  - spec/fixtures/hello/config.ru
188
+ - spec/fixtures/load_rack_env_group/Gemfile
189
+ - spec/fixtures/load_rack_env_group/config.ru
190
+ - spec/fixtures/load_rack_env_group/vendor/my_development_gem/lib/my_development_gem.rb
191
+ - spec/fixtures/load_rack_env_group/vendor/my_development_gem/my_development_gem.gemspec
192
+ - spec/fixtures/load_rack_env_group/vendor/my_foo_gem/lib/my_foo_gem.rb
193
+ - spec/fixtures/load_rack_env_group/vendor/my_foo_gem/my_foo_gem.gemspec
188
194
  - spec/full_reload_spec.rb
195
+ - spec/load_rack_env_spec.rb
189
196
  - spec/normal_running_spec.rb
190
197
  - spec/spec_helper.rb
191
198
  homepage: http://github.com/MicahChalmer/mr-sparkle
192
- licenses: []
199
+ licenses:
200
+ - MIT
193
201
  post_install_message:
194
202
  rdoc_options: []
195
203
  require_paths:
@@ -199,7 +207,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
207
  requirements:
200
208
  - - ! '>='
201
209
  - !ruby/object:Gem::Version
202
- version: 1.9.1
210
+ version: 1.9.3
203
211
  required_rubygems_version: !ruby/object:Gem::Requirement
204
212
  none: false
205
213
  requirements:
@@ -220,6 +228,13 @@ test_files:
220
228
  - spec/fixtures/full_reload/vendor/full_reload_test_gem/lib/full_reload_test_gem.rb
221
229
  - spec/fixtures/hello/Gemfile
222
230
  - spec/fixtures/hello/config.ru
231
+ - spec/fixtures/load_rack_env_group/Gemfile
232
+ - spec/fixtures/load_rack_env_group/config.ru
233
+ - spec/fixtures/load_rack_env_group/vendor/my_development_gem/lib/my_development_gem.rb
234
+ - spec/fixtures/load_rack_env_group/vendor/my_development_gem/my_development_gem.gemspec
235
+ - spec/fixtures/load_rack_env_group/vendor/my_foo_gem/lib/my_foo_gem.rb
236
+ - spec/fixtures/load_rack_env_group/vendor/my_foo_gem/my_foo_gem.gemspec
223
237
  - spec/full_reload_spec.rb
238
+ - spec/load_rack_env_spec.rb
224
239
  - spec/normal_running_spec.rb
225
240
  - spec/spec_helper.rb