Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rolled back to single-repo version of retreat gem

  • Loading branch information...
commit 4116c4b25a0ef7665e024169cd7ac5d1da4528cf 1 parent 33aea5c
@mowat27 mowat27 authored
Showing with 50 additions and 65 deletions.
  1. +3 −5 retreat_gem/bin/retreat
  2. +47 −60 retreat_gem/lib/coderetreat/retreat.rb
View
8 retreat_gem/bin/retreat
@@ -1,7 +1,5 @@
#!/usr/bin/env ruby
-$: << File.dirname(__FILE__)+'/../lib'
-
require 'coderetreat/retreat'
include CodeRetreat
@@ -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
View
107 retreat_gem/lib/coderetreat/retreat.rb
@@ -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?
@@ -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}
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.