Sha256: 36cc641a4b7cf3317779c63e1300b9610179bd7509ead58e65b93dc46b3a77f7

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'stringio'
require 'rexml/document'

module BuildMaster

class SvnInfo
  attr_reader :work_dir, :repository_root
  
  def initialize(work_dir)
    @work_dir = work_dir
    entries = work_dir.dir('.svn').file('entries')
    analyze_entry_file(entries)
  end
  
  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|
      return element.attributes['repos']
    end
  end
  
end

class SvnDriver    
    def SvnDriver::from_path(directory)
        return SvnDriver.new(SvnInfo.new(directory))
    end
    
    def initialize(svn_info)
        @svn_info = svn_info
        @system = svn_info.work_dir.system
    end
    
    def status
        command_for_path('status')
    end
    
    def update
        command_for_path('update')
    end
    
    def commit(comment)
        command_for_path('commit', " -m \"#{comment}\"") 
    end
    
    def tag(tag_name)
        @system.shell("svn copy #{@svn_info.repository_root}/trunk #{@svn_info.repository_root}/tags/#{tag_name} -m \"ruby buildmaster\"")
    end
    
    def checkout(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='')
        @system.shell("svn #{svn_command} #{@svn_info.work_dir.path}#{argument}")
    end
end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
BuildMaster-0.9.0 lib/buildmaster/svn_driver.rb