Class: SvnTransform::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/svn-transform/session.rb

Overview

A simplistic wrapper for Svn::Ra::Session. This takes care of setting up the context and callbacks as well as making the actual connection.

Instance Method Summary collapse

Constructor Details

#initialize(uri, username = nil, password = nil) ⇒ Session

Setup repository information

Parameters

uri<String>

URI of the repository (e.g. svn://example.com/repo)

username<String>

Username, if needed

password<String>

Password, if needed



11
12
13
14
15
# File 'lib/svn-transform/session.rb', line 11

def initialize(uri, username = nil, password = nil)
  @uri = uri
  @username = username
  @password = password
end

Instance Method Details

#callbacksObject

Setup callbacks for Svn::Ra::Session.open.

Returns

Svn::Ra::Callbacks



58
59
60
# File 'lib/svn-transform/session.rb', line 58

def callbacks
  ::Svn::Ra::Callbacks.new(context.auth_baton)
end

#contextObject

Setup, if needed, and return the working context (I don’t really understand all this, but it’s required to work with the working copy).

Returns

Svn::Client::Context

Context for working with working copy



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/svn-transform/session.rb', line 33

def context
  @context || begin
    # Client::Context, which paticularly holds an auth_baton.
    @context = ::Svn::Client::Context.new
    if @username && @password
      # TODO: What if another provider type is needed? Is this plausible?
      @context.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
        cred.username = @username
        cred.password = @password
      end
    elsif URI.parse(@uri).scheme == "file" 
      @context.add_username_prompt_provider(0) do |cred, realm, username, may_save|
        cred.username = @username || "ANON"
      end
    else
      @context.auth_baton = ::Svn::Core::AuthBaton.new()
    end
    @context
  end
end

#sessionObject

Open and return the actual Svn::Ra::Session

Returns

Svn::Ra::Session

A remote access session to a repository.



21
22
23
24
25
26
# File 'lib/svn-transform/session.rb', line 21

def session
  # This will raise some error if connection fails for whatever reason.
  # I don't currently see a reason to handle connection errors here, as I
  # assume the best handling would be to raise another error.
  @session ||= ::Svn::Ra::Session.open(@uri, {}, self.callbacks)
end