Class: SvnFixture::Directory
Overview
A Directory to be added to or edited within the Repository. Normally, this would br done through Directory#dir, in a block given to a Directory or Revision, for example:
SvnFixture.repo('repo_name') do
revision(1, 'msg') do
dir('test-dir') do
prop('name', 'value')
file('file.txt')
end
end
end
In that case, Revision takes care of passing the ctx
argument.
To call SvnFixture::Directory.new directly, you will need to set up a context (instance of Svn::Client::Context) and check out a working copy. SvnFixture.simple_context
is a quick method for settin up a Context.
Assuming an existing checked out working copy:
ctx = SvnFixture.simple_context
d = SvnFixture::Directory.new(ctx, '/full/fs/path/to/dir')
d.prop('propname', 'Value')
Or, call #checkout on Context:
ctx = SvnFixture.simple_context
ctx.checkout('file:///repository/uri', '/fs/path/of/wc')
d = SvnFixture::Directory.new(ctx, '/fs/path/of/wc/to/dir')
d.prop('propname', 'Value')
Instance Method Summary collapse
-
#copy(from, to) ⇒ Object
Copy a File or Directory.
-
#delete(name) ⇒ Object
Delete (and remove from Repository) a child node.
-
#dir(name, &block) ⇒ Object
Create or access a subdirectory.
-
#file(name, &block) ⇒ Object
Create or access a subdirectory.
-
#initialize(ctx, path) ⇒ Directory
constructor
new
is normally called through Directory#dir (a block to a Revision is applied to the root Directory). -
#move(from, to) ⇒ Object
Move a File or Directory.
-
#prop(name, value, recurse = false) ⇒ Object
Set a property for the Directory (see svnbook.red-bean.com/en/1.1/ch07s02.html):.
Methods inherited from File
Constructor Details
#initialize(ctx, path) ⇒ Directory
new
is normally called through Directory#dir (a block to a Revision is applied to the root Directory).
Arguments are:
-
ctx
: An Svn::Client::Context, normally from Repository#ctx -
path
: The path (on the file system) of the Directory in the working copy.
42 43 44 45 46 47 |
# File 'lib/svn-fixture/directory.rb', line 42 def initialize(ctx, path) @ctx = ctx @path = path @path += "/" unless path[-1] == 47 @clean_path = @path[0..-2] # Path without a trailing slash. end |
Instance Method Details
#copy(from, to) ⇒ Object
Copy a File or Directory. From should be an existing node. From and to can be any relative path below the directory.
83 84 85 |
# File 'lib/svn-fixture/directory.rb', line 83 def copy(from, to) @ctx.cp(@path + from, @path + to) end |
#delete(name) ⇒ Object
Delete (and remove from Repository) a child node.
88 89 90 |
# File 'lib/svn-fixture/directory.rb', line 88 def delete(name) @ctx.delete(@path + name) end |
#dir(name, &block) ⇒ Object
Create or access a subdirectory. Takes the name of the subdirectory (not a full path) and an optional block with the subdirectory as self.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/svn-fixture/directory.rb', line 51 def dir(name, &block) path = @path + name unless ::File.directory?(path) FileUtils.mkdir_p(path) @ctx.add(path) end d = self.class.new(@ctx, path) d.instance_eval(&block) if block_given? d end |
#file(name, &block) ⇒ Object
Create or access a subdirectory. Takes the name of the file (not a full path) and an optional block with the File as self.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/svn-fixture/directory.rb', line 64 def file(name, &block) path = @path + name unless ::File.file?(path) FileUtils.touch(path) @ctx.add(path) end f = File.new(@ctx, path) f.instance_eval(&block) if block_given? f end |
#move(from, to) ⇒ Object
Move a File or Directory. From should be an existing node. From and to can be any relative path below the directory.
77 78 79 |
# File 'lib/svn-fixture/directory.rb', line 77 def move(from, to) @ctx.mv(@path + from, @path + to) end |
#prop(name, value, recurse = false) ⇒ Object
Set a property for the Directory (see svnbook.red-bean.com/en/1.1/ch07s02.html):
Parameters
- name<String>
-
The property name (must be “human-readable text”)
- value<String>
-
The value of the property.
- recurse<True, False>
-
Apply this property to descendants?
99 100 101 |
# File 'lib/svn-fixture/directory.rb', line 99 def prop(name, value, recurse = false) @ctx.propset(name, SvnFixture.svn_prop(value), @clean_path, recurse) end |