Commit 8dd60ef9740042cf5e30e40a2ba2c87ebcad201b
- Date: Mon Jul 02 20:59:13 +0000 2007
- Committer: fbos (fbos@d6c2ea82-c31b-0410-8381-e9c44f9824c5)
- Author: fbos (fbos@d6c2ea82-c31b-0410-8381-e9c44f9824c5)
- Commit SHA1: 8dd60ef9740042cf5e30e40a2ba2c87ebcad201b
- Tree SHA1: 1fc0a9c2ab29a48f1ada9de40316df00ca94f14d
New WorkingCopy#cat, #down and #up.
git-svn-id: svn+ssh://rubyforge.org/var/svn/piston/trunk@128 d6c2ea82-c31b-0410-8381-e9c44f9824c5
Commit diff
| |   |
| 6 | 6 | module Piston |
| 7 | 7 | # Represents a Subversion working copy. |
| 8 | 8 | class WorkingCopy |
| 9 | class FileNotFound < StandardError |
| 10 | def initialize(path) |
| 11 | super "File #{path.inspect} could not found" |
| 12 | end |
| 13 | end |
| 14 | |
| 9 | 15 | include Piston::SubversionClient |
| 10 | 16 | |
| 11 | 17 | attr_reader :dir, :path |
| … | … | |
| 146 | 146 | @info ||= YAML.load(svn(:info, wc_path(self.dir))) |
| 147 | 147 | end |
| 148 | 148 | |
| 149 | | def parent |
| 149 | def down(folder) #:nodoc: |
| 150 | self.class.new(self.path + folder, :logger => self.logger) |
| 151 | end |
| 152 | |
| 153 | def up #:nodoc: |
| 150 | 154 | self.class.new(self.path + "..", :logger => self.logger) |
| 151 | 155 | end |
| 152 | 156 | |
| … | … | |
| 172 | 172 | FileUtils.rm_rf(@dir) |
| 173 | 173 | end |
| 174 | 174 | |
| 175 | # Reads the file at +path+ and returns the contents. |
| 176 | # Raises a FileNotFound exception unless the file is accessible. |
| 177 | def cat(path) #:nodoc: |
| 178 | file = wc_path(path) |
| 179 | raise FileNotFound.new(file) unless File.exist?(file) |
| 180 | File.read(file) |
| 181 | end |
| 182 | |
| 175 | 183 | # Ensures +repos_url+ is a URL string or URI object and raises an ArgumentError if not. |
| 176 | 184 | def is_a_url?(repos_url) #:nodoc: |
| 177 | 185 | case repos_url |
| toggle raw diff |
--- a/lib/piston/working_copy.rb
+++ b/lib/piston/working_copy.rb
@@ -6,6 +6,12 @@ require "yaml"
module Piston
# Represents a Subversion working copy.
class WorkingCopy
+ class FileNotFound < StandardError
+ def initialize(path)
+ super "File #{path.inspect} could not found"
+ end
+ end
+
include Piston::SubversionClient
attr_reader :dir, :path
@@ -140,7 +146,11 @@ module Piston
@info ||= YAML.load(svn(:info, wc_path(self.dir)))
end
- def parent
+ def down(folder) #:nodoc:
+ self.class.new(self.path + folder, :logger => self.logger)
+ end
+
+ def up #:nodoc:
self.class.new(self.path + "..", :logger => self.logger)
end
@@ -162,6 +172,14 @@ module Piston
FileUtils.rm_rf(@dir)
end
+ # Reads the file at +path+ and returns the contents.
+ # Raises a FileNotFound exception unless the file is accessible.
+ def cat(path) #:nodoc:
+ file = wc_path(path)
+ raise FileNotFound.new(file) unless File.exist?(file)
+ File.read(file)
+ end
+
# Ensures +repos_url+ is a URL string or URI object and raises an ArgumentError if not.
def is_a_url?(repos_url) #:nodoc:
case repos_url
|