Skip to content

Commit

Permalink
Rolled back to single-repo version of retreat gem
Browse files Browse the repository at this point in the history
  • Loading branch information
mowat27 committed Nov 9, 2011
1 parent 33aea5c commit 4116c4b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 65 deletions.
8 changes: 3 additions & 5 deletions retreat_gem/bin/retreat
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env ruby

$: << File.dirname(__FILE__)+'/../lib'

require 'coderetreat/retreat'

include CodeRetreat
Expand Down Expand Up @@ -38,11 +36,11 @@ action = ARGV.shift
begin
case
when action == "info"
Actions::Info.run!(ARGV)
Actions::Info.run!
when action == "install"
Actions::Install.run!(ARGV)
Actions::Install.run!
when action == "update"
Actions::Update.run!(ARGV)
Actions::Update.run!
when action == "start"
Actions::Start.run!(ARGV)
else
Expand Down
107 changes: 47 additions & 60 deletions retreat_gem/lib/coderetreat/retreat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(*elements)
relative_path = File.join(*elements)
@path = File.expand_path(relative_path)
end

def_file_op :exists?
def_file_op :directory?
def_file_op :file?
Expand Down Expand Up @@ -76,96 +76,79 @@ module Actions
class Action
def initialize
@home = Path.new(Etc.getpwuid.dir, '.retreat')
end

def default_user
'coreyhaines'
end

def repo_url_for user
"https://github.com/#{user}/coderetreat.git"
end

def repo_path user
repo_path = @home.join user
unless repo_path.exists?
puts "Pulling #{user}/coderetreat repo into #{repo_path}..."
Git.clone repo_url_for(user), repo_path
puts "\nInstallation completed! Here is some information..."
end
repo_path
end

def language user, language
repo_path(user).join('starting_points', language)
end

def languages user
repo_path(user).join('starting_points').ls.map{|path| path.basename}
@local_repo = Path.new(Etc.getpwuid.dir, '.retreat', 'coderetreat')
@source_repo = "https://github.com/coreyhaines/coderetreat.git"
@starting_points = @local_repo.join("starting_points")
end
end

class Start < Action
def self.run!(args)
new(args).run!
end

def initialize(args)
super()
@user, @language = args[0].split('/')
@user, @language = default_user, @user unless @language
@language = args[0]
@source = @starting_points.join(@language)
@target = args[1] ? Path.new(args[1]) : Path.new('.')
end

def run!
validate_environment!
language(@user, @language).copy_to(@target)
@source.copy_to(@target)
puts "Created #{@language} iteration starting point at #{@target}"
end

def validate_environment!
raise EnvError.new("No sources found. Try running 'retreat install' first") unless @source.directory?
raise EnvError.new("Cannot create #{@target}") unless @target.dirname.writable?
end
end

class Install < Action
def self.run!(args)
new(args).run!
end

def initialize(args)
super()
@user = args[0] || default_user
def self.run!
new.run!
end

def run!
repo_path @user
Info.run! [@user]
validate_environment!
puts "Pulling coderetreat repo into #{@local_repo}..."
Git.clone @source_repo, @local_repo
puts "\nInstallation completed! Here is some information..."
Info.run!
puts "\nRun 'retreat start <language> [location]' to start a new iteration"
end

def validate_environment!
if @local_repo.exists?
raise EnvError.new("retreat has already been installed. Run 'retreat update' to get the latest starting points.")
end
end
end

class Update < Action
def self.run!(args)
new(args)
def self.run!
new.run!
end

def run!
validate_environment!
puts "Updating sources at #{@local_repo}"
Git.pull @local_repo
end

def initialize(args)
super()
@user = args[0] || default_user
puts "Updating sources at #{repo_path @user}"
Git.pull repo_path(@user)

def validate_environment!
raise EnvError.new("retreat is not installed. Run 'retreat install' to get started.") unless @local_repo.exists?
end
end

class Info < Action
def self.run!(args)
new(args)
def self.run!
new.run!
end

def initialize(args)
super()
@user = args[0] || default_user
def run!
result =<<EOS
#{message}
Expand All @@ -175,13 +158,17 @@ def initialize(args)

def message
result =<<EOS
Source Repo: #{repo_url_for @user}
Local Repo: #{repo_path @user}
Languages Available: #{languages(@user).join(", ")}
Source Repo: #{@source_repo}
Local Repo: #{@local_repo}
Languages Available: #{languages.join(", ")}
EOS

result
end

def languages
@starting_points.ls.map{|path| path.basename}
end
end
end
end

0 comments on commit 4116c4b

Please sign in to comment.