P4RecId (Class)

In: p4table.rb
Parent: Object

Class for creating and formatting record id’s. Normally these are just of the form "<tablename>/<nnnnnn>"

Methods

new   new_from_job   next   seq_str   to_s  

Attributes

seq  [RW] 
table  [RW] 

Public Class methods

Construct a new RecID for the given table name and sequence number

[Source]

     # File p4table.rb, line 230
230:     def initialize( table, seq )
231:         @table = table
232:         if ( seq.kind_of?( String ) )
233:             if ( seq =~ /^0*([1-9]\d+)$/ )
234:                 @seq = $1.to_i
235:             else
236:                 @seq = seq.to_i
237:             end
238:         else
239:             @seq = seq
240:         end
241:     end

Instantiate a new P4RecID from the job name ( "<table>/<id>" ). Used to load existing records.

[Source]

     # File p4table.rb, line 222
222:     def P4RecId.new_from_job( job )
223:         ( table, seq ) = job.split( "/" )
224:         P4RecId.new( P4Table.new( table ), seq )
225:     end

Get the next ID for the specified table using

  1. p4 counter <table>
  2. p4 counter <table> = <n+1>

Yes, this has a race condition, but there’s no atomic get and set operation for Perforce counters.

[Source]

     # File p4table.rb, line 210
210:     def P4RecId.next( table )
211:         p4 = P4Global.tagged
212:         val = p4.run_counter( table.name ).shift.to_i
213:         val += 1
214:         p4.run_counter( table.name, val )
215:         P4RecId.new( table, val )
216:     end

Public Instance methods

Format the sequence number for printing

[Source]

     # File p4table.rb, line 252
252:     def seq_str
253:         sprintf( "%06d", @seq )
254:     end

String representation of an id

[Source]

     # File p4table.rb, line 259
259:     def to_s
260:         @table.name + "/" + seq_str()
261:     end

[Validate]