Module: SvnFixture

Defined in:
lib/svn-fixture.rb,
lib/svn-fixture/file.rb,
lib/svn-fixture/revision.rb,
lib/svn-fixture/directory.rb,
lib/svn-fixture/repository.rb

Defined Under Namespace

Classes: Directory, File, Repository, Revision

Constant Summary collapse

VERSION =
'0.3.0'
CONFIG_DEFAULTS =
{
  :base_path => File.join(Dir.tmpdir, 'svn-fixture')
}

Class Method Summary collapse

Class Method Details

.configObject

SvnFixture::config method returns Hash that can be edited. The only current option is :base_path : The path at which repositories are created. It default to the OS tmp directory, plus “svn-fixture”. For example, “/tmp/svn-fixture”. The repo name is then appended in SvnFixture::Repository.



24
25
26
# File 'lib/svn-fixture.rb', line 24

def config
  @config ||= CONFIG_DEFAULTS.dup
end

.repo(*args, &block) ⇒ Object

.repo is just a shortcut to SvnFixture::Repository.get



46
47
48
# File 'lib/svn-fixture.rb', line 46

def repo(*args, &block)
  SvnFixture::Repository.get(*args, &block)
end

.simple_contextObject

Setup and return a simple ::Svn::Client::Context. This is called by Repository#checkout, but can also be used in called Directory.new or File.new directly. See SvnFixture::File for examples.



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/svn-fixture.rb', line 53

def simple_context
  ctx = ::Svn::Client::Context.new
 
  # I don't understand the auth_baton and log_baton, so I set them here,
  # then use revision properties.
  ctx.add_username_prompt_provider(0) do |cred, realm, username, may_save|
     cred.username = "ANON"
  end
  ctx.set_log_msg_func {|items| [true, ""]}
  ctx
end

.svn_prop(val) ⇒ Object

Return a Date or Time formatted as expected by ::Svn::Client::Context#propset (see svn_time); leave other values alone.



41
42
43
# File 'lib/svn-fixture.rb', line 41

def svn_prop(val)
  val.respond_to?(:strftime) ? svn_time(val) : val
end

.svn_time(val) ⇒ Object

Return time string formatted as expected by ::Svn::Client::Context#propset (example 2009-06-28T12:00:00.000000Z). If val does not respond to strftime, val will first be parsed via Time.parse.



31
32
33
34
35
36
37
# File 'lib/svn-fixture.rb', line 31

def svn_time(val)
  return nil if val.nil?
  val = Time.parse(val) unless val.respond_to?(:strftime)
  val = val.utc if val.respond_to?(:utc)
  usec = val.respond_to?(:usec) ? val.usec : 0
  val.strftime("%Y-%m-%dT%H:%M:%S.") + sprintf('%06dZ', usec)
end