Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

apply rails_env option to both runners, shorter readme.

  • Loading branch information...
commit bc99a928abc3256c2d93139733490dac5f7c53d0 1 parent 3495b1a
Dmytrii Nagirniak authored
25 README.md
View
@@ -1,9 +1,9 @@
# Guard::RailsAssets
-Guard::RailsAssets compiles the assets in Rails 3.1 application automatically when files are modified.
+Guard::RailsAssets compiles the assets within Rails 3.1 application whenever those change.
-Tested on MRI Ruby 1.9.2 (please report if it works on your platform).
+Tested on MRI 1.9.2 (please report if it works on your platform).
If you have any questions please contact me [@dnagir](http://www.ApproachE.com).
@@ -22,25 +22,10 @@ gem 'guard-rails-assets'
Add guard definition to your `Guardfile` by running:
```bash
-$ guard init rails-assets
+$ bundle exec guard init rails-assets
```
-## Rails 3.1
-
-The assets can be compiled using following "runners":
-
-1. rake command (CLI);
-2. loading the actual Rails environment.
-
-In the 1st case - this Guard is not actually using Rails directly while in the 2nd - it loads it explicitly.
-
-Good thing about the 1st approach is that assets will always be same as produced by Rails.
-Bad thing is that it is pretty slow (~10 seconds) because it starts Rails from ground zero.
-
-The 2nd approach is good because it is much faster, but does not reload Rails environment (so you have to restart guard).
-Additionally it relies on a single instance of your app to be loaded, so you can't have multiple guards with different reails configurations.
-
-## Guardfile and Options
+## Options
In addition to the guard configuration, `guard-rails-assets` has options to specify when exacly to precompile assets.
@@ -52,7 +37,7 @@ In addition to the guard configuration, `guard-rails-assets` has options to spec
Also you can set the `:runner` option:
- `:cli` - compile assets using the rake task - the most correct method, but slow.
-- `:rails` - compile assets by loading rails environment (default) - fast, but does not pick up changes.
+- `:rails` - compile assets by loading rails environment (default) - fast, but does not pick up changes. Additionally it relies on a single instance of your app to be loaded, so you can't have multiple guards with different rails configurations.
You can also use `:rails_env` option to specify what Rails environment to use (defaults to 'test').
5 lib/guard/rails-assets/cli_runner.rb
View
@@ -1,10 +1,11 @@
module Guard
class RailsAssets::CliRunner
- def initialize(options)
+ def initialize(options={})
+ @rails_env = (options[:rails_env] || 'test').to_s
end
def compile_assets
- system "bundle exec rake assets:clean assets:precompile"
+ system "RAILS_ENV=#{@rails_env} bundle exec rake assets:clean assets:precompile"
end
end
end
13 spec/guard/rails-assets/cli_runner_spec.rb
View
@@ -2,11 +2,18 @@
describe Guard::RailsAssets::CliRunner do
- subject { Guard::RailsAssets::CliRunner.new({}) }
-
it 'should run the command' do
subject.stub(:system)
- subject.should_receive(:system).with("bundle exec rake assets:clean assets:precompile")
+ subject.should_receive(:system).with("RAILS_ENV=test bundle exec rake assets:clean assets:precompile")
subject.compile_assets
end
+
+ context 'with production environment' do
+ subject { Guard::RailsAssets::CliRunner.new(:rails_env => :production) }
+ it 'should run the command' do
+ subject.stub(:system)
+ subject.should_receive(:system).with("RAILS_ENV=production bundle exec rake assets:clean assets:precompile")
+ subject.compile_assets
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.