Class P4::Map
Description
The P4::Map
class allows users to create and work
with
Helix Core Server
mappings, without requiring a connection to aHelix Core Server.
Class Methods
Map.new ( [ anArray ] ) -> aMap
Constructs a new P4::Map
object.
Map.join ( map1, map2 ) -> aMap
Join two P4::Map
objects and create a third.
The new map is composed of the left-hand side of the first mapping, as joined to the right-hand side of the second mapping. For example:
# Map depot syntax to client syntax
client_map = P4::Map.new
client_map.insert( "//depot/main/...", "//client/..." )
# Map client syntax to local syntax
client_root = P4::Map.new
client_root.insert( "//client/...", "/home/bruno/workspace/..." )
# Join the previous mappings to map depot syntax to local syntax
local_map = P4::Map.join( client_map, client_root )
local_path = local_map.translate( "//depot/main/www/index.html" )
# local_path is now /home/bruno/workspace/www/index.html
Instance Methods
map.clear -> true
Empty a map.
map.count -> anInteger
Return the number of entries in a map.
map.empty? -> aBool
Test whether a map object is empty.
map.insert( aString, [ aString ] ) -> aMap
Inserts an entry into the map.
May be called with one or two arguments. If called with one argument, the string is assumed to be a string containing either a half-map, or a string containing both halves of the mapping. In this form, mappings with embedded spaces must be quoted. If called with two arguments, each argument is assumed to be half of the mapping, and quotes are optional.
# called with two arguments:
map.insert( "//depot/main/...", "//client/..." )
# called with one argument containing both halves of the mapping:
map.insert( "//depot/live/... //client/live/..." )
# called with one argument containing a half-map:
# This call produces the mapping "depot/... depot/..."
map.insert( "depot/..." )
map.translate ( aString, [ aBool ] )-> aString
Translate a string through a map, and return the result. If the optional second argument is true, translate forward, and if it is false, translate in the reverse direction. By default, translation is in the forward direction.
map.includes? ( aString ) -> aBool
Tests whether a path is mapped or not.
if( map.includes?( "//depot/main/..." ) )
...
end
map.reverse -> aMap
Return a new P4::Map
object with the left and right
sides of the mapping swapped. The original object is unchanged.
map.lhs -> anArray
Returns the left side of a mapping as an array.
map.rhs -> anArray
Returns the right side of a mapping as an array.
map.to_a -> anArray
Returns the map as an array.