class R10K::Source::SVN

This class implements a source for SVN environments.

An SVN source generates environments by enumerating the branches and trunk for a given SVN remote. SVN repositories must conform to the conventional SVN repository structure with the directories trunk/, branches/, and optionally tags/ in the root of the repository. The trunk/ directory is specifically mapped to the production environment, branches are created as environments with the name of the given branch.

@see svnbook.red-bean.com/en/1.7/svn.branchmerge.maint.html @since 1.3.0

Attributes

password[R]

@!attribute [r] password

@return [String, nil] The SVN password to be passed to the underlying SVN commands
@api private
remote[R]

@!attribute [r] remote

@return [String] The URL to the base directory of the SVN repository
svn_remote[R]

@!attribute [r] #svn_remote

@api private
@return [R10K::SVN::Remote]
username[R]

@!attribute [r] username

@return [String, nil] The SVN username to be passed to the underlying SVN commands
@api private

Public Class Methods

new(name, basedir, options = {}) click to toggle source

Initialize the given source.

@param name [String] The identifier for this source. @param basedir [String] The base directory where the generated environments will be created. @param options [Hash] An additional set of options for this source.

@option options [Boolean] :prefix Whether to prefix the source name to the

environment directory names. Defaults to false.

@option options [String] :remote The URL to the base directory of the SVN repository @option options [String] :username The SVN username @option options [String] :password The SVN password

Calls superclass method R10K::Source::Base.new
# File lib/r10k/source/svn.rb, line 53
def initialize(name, basedir, options = {})
  super

  setopts(options, {:remote => :self, :username => :self, :password => :self})
  @environments = []
  @svn_remote = R10K::SVN::Remote.new(@remote, :username => @username, :password => @password)
end

Public Instance Methods

desired_contents() click to toggle source

List all environments that should exist in the basedir for this source @note This is required by {R10K::Util::Basedir} @return [Array<String>]

# File lib/r10k/source/svn.rb, line 94
def desired_contents
  @environments.map {|env| env.dirname }
end
environments() click to toggle source

Enumerate the environments associated with this SVN source.

@return [Array<R10K::Environment::SVN>] An array of environments created

from this source.
# File lib/r10k/source/svn.rb, line 65
def environments
  if @environments.empty?
    @environments = generate_environments()
  end

  @environments
end
generate_environments() click to toggle source

Generate a list of currently available SVN environments

@todo respect environment name corrections

@api protected @return [Array<R10K::Environment::SVN>] An array of environments created

from this source.
# File lib/r10k/source/svn.rb, line 80
def generate_environments
  names_and_paths.map do |(branch, path)|
    options = {
      :remote   => path,
      :username => @username,
      :password => @password
    }
    R10K::Environment::SVN.new(branch.name, @basedir, branch.dirname, options)
  end
end

Private Instance Methods

names_and_paths() click to toggle source
# File lib/r10k/source/svn.rb, line 102
def names_and_paths
  branches = []

  opts = {:prefix => @prefix, :correct => false, :validate => false, :source => @name}

  branches << [R10K::Environment::Name.new('production', opts), "#{@remote}/trunk"]
  @svn_remote.branches.each do |branch|
    branches << [R10K::Environment::Name.new(branch, opts), "#{@remote}/branches/#{branch}"]
  end

  branches
end