P4RecFile (Class)

In: p4table.rb
Parent: Object

*******************************************************************************

 Class for representing files that are versioned in the depot.

*******************************************************************************

Methods

add   delete   depot_path   depot_path=   edit   exists=   exists?   mkdir   new   read   to_s   write   ws_path  

Attributes

name  [R] 
p4  [R] 
rec  [R] 

Public Class methods

[Source]

     # File p4table.rb, line 122
122:     def initialize( p4, name, rec  )
123:         @p4            = p4
124:         @name          = name
125:         @rec           = rec
126:         @exists        = false
127:         @depot_path    = nil
128:         @ws_path       = nil
129:     end

Public Instance methods

[Source]

     # File p4table.rb, line 181
181:     def add
182:         if ( exists? )
183:             raise( RuntimeError, "Can't open existing file for add", caller )
184:         end
185:         p4.run_add( ws_path() )
186:     end

[Source]

     # File p4table.rb, line 203
203:     def delete
204:         if ( ! exists? )
205:             raise( RuntimeError, "Can't delete non-existent file", caller )
206:         end
207: 
208:         p4.run_sync( depot_path() )
209:         p4.run_delete( depot_path() )
210:     end

[Source]

     # File p4table.rb, line 158
158:     def depot_path
159:         return @depot_path if @depot_path
160:         table_path = @rec.table.storage_map( @rec ).join( "/" )
161:         @depot_path = [ DEPOT_ROOT_PATH, table_path, @rec.id.seq_str, @name ].join( "/" )
162:     end

[Source]

     # File p4table.rb, line 151
151:     def depot_path=( path )
152:         @depot_path = path
153:     end

[Source]

     # File p4table.rb, line 191
191:     def edit
192:         if ( ! exists? )
193:             raise( RuntimeError,"Can't open non-existent file for edit", caller)
194:         end
195: 
196:         p4.run_sync( depot_path() )
197:         p4.run_edit( depot_path() )
198:     end

[Source]

     # File p4table.rb, line 174
174:     def exists=( bool )
175:         @exists = bool
176:     end

[Source]

     # File p4table.rb, line 167
167:     def exists?
168:         @exists
169:     end

[Source]

     # File p4table.rb, line 235
235:     def mkdir
236:         dirs = ws_path.split( SEP )
237:         dirs.pop
238:         dir = ""
239:         dirs.each do
240:             |d|
241:             dir += d + SEP
242:             Dir.mkdir( dir ) unless File.directory?( dir )
243:         end
244:     end

[Source]

     # File p4table.rb, line 215
215:     def read
216:         p4.run_sync( depot_path() )
217:         f = File.open( ws_path, "r" )
218:         buf = f.read
219:         f.close
220:         return buf
221:     end

[Source]

     # File p4table.rb, line 249
249:     def to_s
250:         depot_file
251:     end

[Source]

     # File p4table.rb, line 226
226:     def write( string )
227:         p4.run_sync( depot_path() )
228:         mkdir()
229:         File.open( ws_path, "w" ) { |f| f.write( string ) }
230:     end

[Source]

     # File p4table.rb, line 137
137:     def ws_path
138:         return @ws_path if ( @ws_path )
139: 
140:         root = p4.fetch_client[ "Root" ]
141:         path = depot_path.sub( DEPOT_ROOT_PATH, root )
142:         @ws_path = path.gsub!( "/", SEP )
143:     end

[Validate]