Class: Perforce2Svn::Perforce::PerforceFile
- Inherits:
-
Object
- Object
- Perforce2Svn::Perforce::PerforceFile
- Includes:
- Logging
- Defined in:
- lib/perforce2svn/perforce/perforce_file.rb
Overview
The collection of properties about a Perforce file
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#binary? ⇒ Boolean
Is this a binary file?.
-
#contents ⇒ Object
Pulls the file contents for a given path for the specific file revision.
-
#deleted? ⇒ Boolean
Was it deleted in the last commit?.
-
#initialize(revision, src, dest, type, action) ⇒ PerforceFile
constructor
A new instance of PerforceFile.
-
#streamed_contents(&block) ⇒ Object
Pull a stream from a file at a specified file revision.
-
#symlink? ⇒ Boolean
Is this a symlink.
-
#symlink_target ⇒ Object
Retrieves the target of a symlink.
- #to_s ⇒ Object
Methods included from Logging
Constructor Details
#initialize(revision, src, dest, type, action) ⇒ PerforceFile
Returns a new instance of PerforceFile.
13 14 15 16 17 18 19 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 13 def initialize(revision, src, dest, type, action) @revision = revision @src = src @dest = dest @type = type @action = action end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
11 12 13 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 11 def action @action end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
11 12 13 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 11 def dest @dest end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
11 12 13 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 11 def revision @revision end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
11 12 13 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 11 def src @src end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 11 def type @type end |
Instance Method Details
#binary? ⇒ Boolean
Is this a binary file?
22 23 24 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 22 def binary? type =~ /binary/ end |
#contents ⇒ Object
Pulls the file contents for a given path for the specific file revision
49 50 51 52 53 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 49 def contents streamed_contents do |stream| return stream.read end end |
#deleted? ⇒ Boolean
Was it deleted in the last commit?
32 33 34 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 32 def deleted? action == 'delete' end |
#streamed_contents(&block) ⇒ Object
Pull a stream from a file at a specified file revision
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 56 def streamed_contents(&block) raise Perforce2Svn::P4Error, "Requires a block to pull the file stream" unless block_given? log.debug { "PERFORCE: Reading file: #{@src}\##{@revision}" } tmpfile = File.join(Dir.tmpdir, ".p4file-#{rand}") begin P4Depot.instance.query do |p4| p4.run('print', '-o', tmpfile, '-q', "#{@src}\##{@revision}") end if !File.file? tmpfile raise Perforce2Svn::P4Error, "Unable to retrieve the file contents: #{src}\##{revision}" end mode = binary? ? 'rb' : 'r' File.open(tmpfile, mode) do |file| yield file end ensure if File.file? tmpfile File.delete(tmpfile) end end end |
#symlink? ⇒ Boolean
Is this a symlink
27 28 29 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 27 def symlink? type =~ /symlink/ end |
#symlink_target ⇒ Object
Retrieves the target of a symlink
41 42 43 44 45 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 41 def symlink_target p4query do |p4| return p4.run('print', '-q', "#{@src}\##{@revision}")[0].strip end end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/perforce2svn/perforce/perforce_file.rb', line 36 def to_s "(#{@action}:#{@type}\##{@revision})\t#{@src}" end |