class P4::Spec
*****************************************************************************
The P4::Spec class holds the fields in a Perforce spec
*****************************************************************************
Public Class Methods
new( fieldmap = nil )
click to toggle source
# File lib/P4.rb, line 435 def initialize( fieldmap = nil ) @fields = fieldmap end
Public Instance Methods
[]=( key, value )
click to toggle source
Override the default assignment method. This implementation ensures that any fields defined are valid ones for this type of spec.
Calls superclass method
# File lib/P4.rb, line 444 def []=( key, value ) if( self.has_key?( key ) || @fields == nil ) super( key, value ) elsif( @fields.has_key?( key.downcase ) ) super( @fields[ key.downcase ], value ) else raise( P4Exception, "Invalid field: #{key}" ) end end
method_missing( m, *a )
click to toggle source
Implement accessor methods for the fields in the spec. The accessor methods are all prefixed with '_' to avoid conflicts with the Hash class' namespace. This is a little ugly, but we gain a lot by subclassing Hash so it's worth it.
# File lib/P4.rb, line 467 def method_missing( m, *a ) k = m.to_s.downcase # Check if we're being asked for 'to_ary'. If so, raise 'NoMethodError'. raise NoMethodError if( k == "to_ary" ) if( k[0..0] != "_" ) raise( RuntimeError, "undefined method `#{m.to_s}' for object of " + "class #{self.class.to_s}" ) end k = k[ 1..-1 ] if( k =~ /(.*)=$/ ) if( a.length() == 0 ) raise( P4Exception, "Method P4##{m} requires an argument" ); end k = $1 if( @fields == nil || @fields.has_key?( k ) ) return self[ @fields[ k ] ] = a.shift end elsif( self.has_key?( m.to_s ) ) return self[ m.to_s ] elsif( @fields.has_key?( k ) ) return self[ @fields[ k ] ] end raise( P4Exception, "Invalid field: #{$1}" ) end
permitted_fields()
click to toggle source
Return the list of the fields that are permitted in this spec
# File lib/P4.rb, line 457 def permitted_fields @fields.values end