Merge branch 'master' of github.com:johnbintz/penchant
This commit is contained in:
commit
f7738f3d42
11
README.md
11
README.md
|
@ -43,6 +43,17 @@ It then runs `bundle install`.
|
|||
|
||||
You can also run `penchant gemfile ENV`.
|
||||
|
||||
### After-`gemfile` hooks?
|
||||
|
||||
Drop a file called `.penchant` in your project directory. It'll get executed every time you switch environments using
|
||||
Penchant. I use it to tell my Hydra clients to sync and update their Gemfiles, too:
|
||||
|
||||
``` ruby
|
||||
# rake knows if you need "bundle exec" or not.
|
||||
|
||||
rake "hydra:sync hydra:remote:bundle"
|
||||
```
|
||||
|
||||
### What environment are you currently using in that Gemfile?
|
||||
|
||||
`head -n 1` that puppy, or `penchant gemfile-env`.
|
||||
|
|
|
@ -28,7 +28,7 @@ class PenchantCLI < Thor
|
|||
def gemfile(env = get_current_env)
|
||||
if env
|
||||
puts "[penchant] Rebunding for #{env} environment..."
|
||||
!Penchant::Gemfile.do_full_env_switch!(env)
|
||||
Penchant::Gemfile.do_full_env_switch!(env)
|
||||
end
|
||||
|
||||
gemfile = Penchant::Gemfile.new
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module Penchant
|
||||
autoload :Gemfile, 'penchant/gemfile'
|
||||
autoload :DotPenchant, 'penchant/dot_penchant'
|
||||
end
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
module Penchant
|
||||
class DotPenchant
|
||||
class << self
|
||||
def run(env = nil)
|
||||
dot_penchant = new
|
||||
dot_penchant.run(env)
|
||||
dot_penchant
|
||||
end
|
||||
end
|
||||
|
||||
def run(env = nil)
|
||||
instance_eval(File.read('.penchant'))
|
||||
end
|
||||
|
||||
def rake(*tasks)
|
||||
command = [ "rake", *tasks ]
|
||||
command.unshift("bundle exec") if gemfile?
|
||||
Kernel.system command.join(' ')
|
||||
end
|
||||
|
||||
private
|
||||
def gemfile?
|
||||
File.file?('Gemfile')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -7,6 +7,8 @@ module Penchant
|
|||
class << self
|
||||
def do_full_env_switch!(env)
|
||||
gemfile = Penchant::Gemfile.new
|
||||
gemfile.run_dot_penchant!(env)
|
||||
|
||||
if !gemfile.has_gemfile_erb?
|
||||
return false
|
||||
end
|
||||
|
@ -27,6 +29,10 @@ module Penchant
|
|||
File.file?('Gemfile')
|
||||
end
|
||||
|
||||
def has_dot_penchant?
|
||||
File.file?('.penchant')
|
||||
end
|
||||
|
||||
def gemfile_erb_path
|
||||
file_in_path('Gemfile.erb')
|
||||
end
|
||||
|
@ -50,6 +56,10 @@ module Penchant
|
|||
end
|
||||
end
|
||||
|
||||
def run_dot_penchant!(env)
|
||||
DotPenchant.run(env || environment) if has_dot_penchant?
|
||||
end
|
||||
|
||||
private
|
||||
def file_in_path(file)
|
||||
File.join(@path, file)
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Penchant::DotPenchant do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
describe '.run' do
|
||||
before do
|
||||
File.open('.penchant', 'wb') { |fh|
|
||||
fh.puts "@did_run = env"
|
||||
}
|
||||
end
|
||||
|
||||
it 'should run the file in the environment' do
|
||||
dot_file = Penchant::DotPenchant.run(:this)
|
||||
|
||||
dot_file.instance_variable_get(:@did_run).should == :this
|
||||
end
|
||||
end
|
||||
|
||||
let(:dot_file) { described_class.new }
|
||||
|
||||
describe '#rake' do
|
||||
context 'without Gemfile' do
|
||||
before do
|
||||
Kernel.expects(:system).with('rake task1 task2')
|
||||
end
|
||||
|
||||
it 'should run the rake task via system' do
|
||||
dot_file.rake("task1", "task2")
|
||||
end
|
||||
end
|
||||
|
||||
context 'with Gemfile' do
|
||||
before do
|
||||
File.open('Gemfile', 'wb')
|
||||
Kernel.expects(:system).with('bundle exec rake task1 task2')
|
||||
end
|
||||
|
||||
it 'should run the rake task via system' do
|
||||
dot_file.rake("task1", "task2")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -103,6 +103,20 @@ ERB
|
|||
File.read('Gemfile').should_not include('not')
|
||||
File.read('Gemfile').should include('all')
|
||||
end
|
||||
|
||||
it { should_not have_dot_penchant }
|
||||
|
||||
context 'with .penchant' do
|
||||
before do
|
||||
File.open('.penchant', 'wb')
|
||||
end
|
||||
|
||||
it { should have_dot_penchant }
|
||||
|
||||
it 'should process the file' do
|
||||
subject.switch_to!(:not)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue