lib/buildmaster/svn_driver.rb in BuildMaster-0.8.1 vs lib/buildmaster/svn_driver.rb in BuildMaster-0.9.0
- old
+ new
@@ -2,47 +2,42 @@
require 'rexml/document'
module BuildMaster
class SvnInfo
- attr_reader :path, :repository_root
+ attr_reader :work_dir, :repository_root
- def initialize(path)
- @path = path
- analyze_entry_file(File.join(path, ".svn", "entries"))
+ def initialize(work_dir)
+ @work_dir = work_dir
+ entries = work_dir.dir('.svn').file('entries')
+ analyze_entry_file(entries)
end
- def analyze_entry_file(path)
- File.open(path, 'r') do |file|
+ def analyze_entry_file(entry_file)
+ @repository_root = entry_file.read do |file|
parse_xml_load_repository_root(file)
end
end
private
def parse_xml_load_repository_root(file)
xml = REXML::Document.new(file)
xml.root.each_element_with_attribute('name', '', 1) do |element|
- @repository_root = element.attributes['repos']
+ return element.attributes['repos']
end
end
end
-class SvnDriver
- include Shell
-
+class SvnDriver
def SvnDriver::from_path(directory)
return SvnDriver.new(SvnInfo.new(directory))
end
- def initialize(svn_info, &command_runner)
+ def initialize(svn_info)
@svn_info = svn_info
- if (command_runner)
- @command_runner = command_runner
- else
- @command_runner = Proc.new {|command| run(command)}
- end
+ @system = svn_info.work_dir.system
end
def status
command_for_path('status')
end
@@ -54,24 +49,23 @@
def commit(comment)
command_for_path('commit', " -m \"#{comment}\"")
end
def tag(tag_name)
- run_command("svn copy #{@svn_info.repository_root}/trunk #{@svn_info.repository_root}/tags/#{tag_name} -m \"ruby buildmaster\"")
+ @system.shell("svn copy #{@svn_info.repository_root}/trunk #{@svn_info.repository_root}/tags/#{tag_name} -m \"ruby buildmaster\"")
end
def checkout(output)
- run_command("svn checkout #{@svn_info.repository_root}/trunk #{output}")
+ @system.shell("svn checkout #{@svn_info.repository_root}/trunk #{output}")
end
def command(command)
command_for_path(command)
end
private
-
def command_for_path(svn_command, argument='')
- run_command("svn #{svn_command} #{@svn_info.path}#{argument}")
+ @system.shell("svn #{svn_command} #{@svn_info.work_dir.path}#{argument}")
end
end
end
\ No newline at end of file