wow, even cooler\!

This commit is contained in:
John Bintz 2012-06-07 10:48:27 -04:00
parent 7f2e0d6301
commit f4cc4ec0a7
10 changed files with 113 additions and 7 deletions

View File

@ -63,6 +63,22 @@ class PenchantCLI < Thor
puts get_current_env
end
desc "bootstrap [DIR = ..]", "Download all referred-to git repos to the specified directory"
def bootstrap(dir = '..')
Penchant::Gemfile.defined_git_repos.each do |repo|
puts "Cloning #{repo} to #{dir}."
repo.clone_to(dir)
end
end
def method_missing(method, *args)
if Penchant::Gemfile.available_environments.include?(method)
gemfile(method, *args)
else
super(method, *args)
end
end
no_tasks do
def get_current_env
gemfile = Penchant::Gemfile.new

View File

@ -157,3 +157,30 @@ Feature: Gemfiles
"""
Scenario: Get the list of environments defined
Given I have the file "Gemfile.penchant" with the content:
"""
env :cat do
gem 'one', :path => '../%s'
end
env :dog do
gem 'two', :path => '../%s'
end
"""
When I request the list of environments available
Then I should get the following environments:
| cat |
| dog |
@wip
Scenario: Get the list of git repos defined
Given I have the file "Gemfile.penchant" with the content:
"""
gem 'one', :path => '../%s'
gem 'two', :git => 'git://github.cats/%s.git'
"""
When I request the list of git repositories
Then I should get the following repositories:
| git://github.cats/two.git |

View File

@ -0,0 +1,3 @@
Then /^I should get the following environments:$/ do |table|
@environments.collect(&:to_s).sort.should == table.raw.flatten.sort
end

View File

@ -0,0 +1,4 @@
Then /^I should get the following repositories:$/ do |table|
@repos.collect(&:to_s).sort.should == table.raw.flatten.sort
end

View File

@ -0,0 +1,3 @@
When /^I request the list of environments available$/ do
@environments = Penchant::Gemfile.available_environments
end

View File

@ -0,0 +1,3 @@
When /^I request the list of git repositories$/ do
@repos = Penchant::Gemfile.defined_git_repos
end

View File

@ -1,4 +1,5 @@
module Penchant
autoload :Gemfile, 'penchant/gemfile'
autoload :Repo, 'penchant/repo'
autoload :DotPenchant, 'penchant/dot_penchant'
end

View File

@ -17,17 +17,26 @@ module Penchant
end
def self.pre_switch(env, deployment = false)
gemfile = Penchant::Gemfile.new
gemfile = new
return false if !gemfile.has_processable_gemfile?
gemfile.run_dot_penchant!(env, deployment)
gemfile
end
def self.available_environments
new.available_environments
end
def self.defined_git_repos
new.defined_git_repos
end
def current_env ; @env ; end
def initialize(path = Dir.pwd)
@path = path
@env = environment
end
def gemfile_path
@ -75,7 +84,7 @@ module Penchant
end
class FileProcessor
attr_reader :environment, :is_deployment
attr_reader :environment, :is_deployment, :available_environments, :defined_git_repos
def self.result(data, *args)
new(data).result(*args)
@ -91,6 +100,8 @@ module Penchant
def initialize(data)
@data = data
@available_environments = []
@defined_git_repos = []
end
def result(_env, _is_deployment)
@ -105,6 +116,8 @@ module Penchant
end
def env(*args)
@available_environments += args
yield if args.include?(environment)
end
@ -220,6 +233,10 @@ module Penchant
args = [ gem_name.first ]
args << options if !options.empty?
if options[:git]
@defined_git_repos << Penchant::Repo.new(options[:git])
end
@output << %{gem #{args_to_string(args)}}
end
@ -254,10 +271,20 @@ module Penchant
end
end
def available_environments
process
builder.available_environments
end
def defined_git_repos
process
builder.defined_git_repos
end
def switch_to!(gemfile_env = nil, deployment = false)
@env, @is_deployment = gemfile_env, deployment
output = [ header, process(template) ]
output = [ header, process ]
File.open(gemfile_path, 'wb') { |fh| fh.print output.join("\n") }
end
@ -289,15 +316,21 @@ module Penchant
File.join(@path, file)
end
def process(template)
builder = case File.extname(processable_gemfile_path)
def process
builder.result(@env, @is_deployment)
end
def builder
return @builder if @builder
klass = case File.extname(processable_gemfile_path)
when '.penchant'
PenchantFile
when '.erb'
ERBFile
end
builder.result(template, @env, @is_deployment)
@builder = klass.new(template)
end
def template

16
lib/penchant/repo.rb Normal file
View File

@ -0,0 +1,16 @@
module Penchant
class Repo
def initialize(url)
@url = url
end
def clone_to(dir)
Dir.chdir(dir) do
system %{git clone #{@url}}
end
end
def to_s ; @url ; end
end
end

View File

@ -150,7 +150,7 @@ ERB
end
describe '#switch_to!' do
let(:template) { 'template' }
let(:template) { 'source' }
let(:gemfile_path) { 'gemfile path' }
let(:header) { 'header' }