Class: R10K::Source::SVN

Inherits:
Base
  • Object
show all
Includes:
Logging, Util::Purgeable
Defined in:
lib/r10k/source/svn.rb

Overview

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.

Defined Under Namespace

Classes: BranchName

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Base

#basedir, #name, #prefix

Instance Method Summary collapse

Methods included from Logging

formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level

Methods included from Util::Purgeable

#pending_contents, #purge!, #stale_contents

Methods inherited from Base

#preload!

Constructor Details

#initialize(name, basedir, options = {}) ⇒ SVN

Initialize the given source.

Parameters:

  • name (String)

    The identifier for this source.

  • basedir (String)

    The base directory where the generated environments will be created.

  • options (Hash) (defaults to: {})

    An additional set of options for this source.

Options Hash (options):

  • :prefix (Boolean)

    Whether to prefix the source name to the environment directory names. Defaults to false.

  • :remote (String)

    The URL to the base directory of the SVN repository

Since:

  • 1.3.0



39
40
41
42
43
44
45
46
# File 'lib/r10k/source/svn.rb', line 39

def initialize(name, basedir, options = {})
  super

  @remote = options[:remote]
  @environments = []

  @svn_remote = R10K::SVN::Remote.new(@remote)
end

Instance Attribute Details

#remoteObject (readonly)

Since:

  • 1.3.0



23
24
25
# File 'lib/r10k/source/svn.rb', line 23

def remote
  @remote
end

#svn_remoteObject (readonly)

Since:

  • 1.3.0



28
29
30
# File 'lib/r10k/source/svn.rb', line 28

def svn_remote
  @svn_remote
end

Instance Method Details

#current_contentsObject

Since:

  • 1.3.0



81
82
83
84
85
# File 'lib/r10k/source/svn.rb', line 81

def current_contents
  Dir.glob(File.join(@basedir, '*')).map do |fname|
    File.basename fname
  end
end

#desired_contentsArray<String>

Note:

This implements a required method for the Purgeable mixin

List all environments that should exist in the basedir for this source

Returns:

  • (Array<String>)

Since:

  • 1.3.0



90
91
92
# File 'lib/r10k/source/svn.rb', line 90

def desired_contents
  @environments.map {|env| env.dirname }
end

#environmentsArray<R10K::Environment::SVN>

Enumerate the environments associated with this SVN source.

Returns:

Since:

  • 1.3.0



52
53
54
55
56
57
58
# File 'lib/r10k/source/svn.rb', line 52

def environments
  if @environments.empty?
    @environments = generate_environments()
  end

  @environments
end

#generate_environmentsArray<R10K::Environment::SVN>

TODO:

respect environment name corrections

Generate a list of currently available SVN environments

Returns:

Since:

  • 1.3.0



67
68
69
70
71
72
73
# File 'lib/r10k/source/svn.rb', line 67

def generate_environments

  branch_names.map do |branch|
    R10K::Environment::SVN.new(branch.name, @basedir, branch.dirname,
                               { :remote => branch.remote })
  end
end

#managed_directoryObject

Since:

  • 1.3.0



77
78
79
# File 'lib/r10k/source/svn.rb', line 77

def managed_directory
  @basedir
end