start work on dotfile hook suttport
This commit is contained in:
parent
508597a9be
commit
c4407f1690
@ -1,3 +1,4 @@
|
||||
module Penchant
|
||||
autoload :Gemfile, 'penchant/gemfile'
|
||||
autoload :DotPenchant, 'penchant/dot_penchant'
|
||||
end
|
||||
|
16
lib/penchant/dot_penchant.rb
Normal file
16
lib/penchant/dot_penchant.rb
Normal file
@ -0,0 +1,16 @@
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -27,6 +27,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
|
||||
@ -48,6 +52,8 @@ module Penchant
|
||||
|
||||
fh.print ERB.new(template).result(binding)
|
||||
end
|
||||
|
||||
run_dot_penchant!(gemfile_env) if has_dot_penchant?
|
||||
end
|
||||
|
||||
private
|
||||
@ -58,6 +64,10 @@ module Penchant
|
||||
def env(check, &block)
|
||||
instance_eval(&block) if check.to_s == @env.to_s
|
||||
end
|
||||
|
||||
def run_dot_penchant!(env)
|
||||
DotPenchant.run(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
20
spec/lib/penchant/dot_penchant_spec.rb
Normal file
20
spec/lib/penchant/dot_penchant_spec.rb
Normal file
@ -0,0 +1,20 @@
|
||||
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
|
||||
end
|
||||
|
@ -103,6 +103,22 @@ 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.expects(:run_dot_penchant!).with(:not)
|
||||
|
||||
subject.switch_to!(:not)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user