class SAPNW::RFC::Parameter

Base class for all Parameter types

Attributes

decimals[R]
direction[R]
len[R]
name[R]
typdef[R]
type[R]
ulen[R]
value[R]

Public Instance Methods

method_missing(methid, *rest, &block) click to toggle source

#method_missing is used to pass on any method call to a parameter to the underlying native Ruby data type

# File lib/sapnwrfc/parameters.rb, line 137
def method_missing(methid, *rest, &block)
  meth = methid.id2name
  #$stderr.print "method_missing: #{meth}\n"
  #$stderr.print "parameters: #{@parameters.keys.inspect}\n"
  if block
    @value.send(meth, &block)
  else
    #$stderr.print "Export method_missing - no block: #{meth}\n"
    @value.send(meth, *rest)
  end
end
value=(val=nil) click to toggle source

value setting for parameters - does basic Type checking to preserve sanity for the underlying C extension

# File lib/sapnwrfc/parameters.rb, line 151
                def value=(val=nil)
                        #$stderr.print "setting: #{@name} type: #{@type} value: #{val}/#{val.class}\n"
case @type
                          when SAPNW::RFC::INT, SAPNW::RFC::INT2, SAPNW::RFC::INT1
    unless val.is_a?(Fixnum)
                                    raise TypeError, "Must be Fixnum for INT, INT1, and INT2 (#{@name}/#{@type}/#{val.class})\n"
                                        end
                          when SAPNW::RFC::NUM
    unless val.is_a?(String)
                                    raise TypeError, "Must be String for NUMC (#{@name}/#{@type}/#{val.class})\n"
                                        end
                          when SAPNW::RFC::BCD
    unless val.is_a?(Float) || val.is_a?(Fixnum) || val.is_a?(Bignum)
                                    raise TypeError, "Must be FLoat or *NUM for BCD (#{@name}/#{@type}/#{val.class})\n"
                                        end
                                        val = val.to_s
                          when SAPNW::RFC::FLOAT
    unless val.is_a?(Float)
                                    raise TypeError, "Must be FLoat for FLOAT (#{@name}/#{@type}/#{val.class})\n"
                                        end
                          when SAPNW::RFC::STRING, SAPNW::RFC::XSTRING
    unless val.is_a?(String)
                                    raise TypeError, "Must be String for STRING, and XSTRING (#{@name}/#{@type}/#{val.class})\n"
                                        end
                          when SAPNW::RFC::BYTE
    unless val.is_a?(String)
                                    raise TypeError, "Must be String for BYTE (#{@name}/#{@type}/#{val.class})\n"
                                        end
                          when SAPNW::RFC::CHAR, SAPNW::RFC::DATE, SAPNW::RFC::TIME
    unless val.is_a?(String)
                                    raise TypeError, "Must be String for CHAR, DATE, and TIME (#{@name}/#{@type}/#{val.class})\n"
                                        end
                          when SAPNW::RFC::TABLE
    unless val.is_a?(Array)
                    raise TypeError, "Must be Array for table value (#{@name}/#{val.class})\n"
                        end
                        cnt = 0
                  val.each do |row|
                          cnt += 1
      unless row.is_a?(Hash)
                      raise TypeError, "Must be Hash for table row value (#{@name}/#{cnt}/#{row.class})\n"
                          end
                        end
                          when SAPNW::RFC::STRUCTURE
    unless val.is_a?(Hash)
                                    raise TypeError, "Must be a Hash for a Structure Type (#{@name}/#{@type}/#{val.class})\n"
                                        end
                                else # anything - barf
                                  raise "unknown SAP data type (#{@name}/#{@type})\n"
                        end
                        @value = val
                        return val
                end

Public Class Methods

new(*parms) click to toggle source
constructor called only from the SAPNW::RFC::Connector#discover process

def initialize(funcdesc, name, type, len, ulen, decimals)

# File lib/sapnwrfc/parameters.rb, line 90
def initialize(*parms)
        parms = parms.first if parms.class == Array and parms.first.class == Hash
  case parms
          when Array
                  # this way happens when the interface of the parameter has been discover()ed
                  funcdesc, name, type, len, ulen, decimals, typedef = parms
                when Hash
                  # This way happens when a parameter is being manually constructed
                  raise "Missing parameter :name => #{parms.inspect}\n" unless parms.has_key?(:name)
                  raise "Missing parameter :type => #{parms.inspect}\n" unless parms.has_key?(:type)
                        case parms[:type]
                          when SAPNW::RFC::CHAR, SAPNW::RFC::DATE, SAPNW::RFC::BCD, SAPNW::RFC::TIME, SAPNW::RFC::BYTE, SAPNW::RFC::TABLE, SAPNW::RFC::NUM, SAPNW::RFC::FLOAT, SAPNW::RFC::INT, SAPNW::RFC::INT2, SAPNW::RFC::INT1, SAPNW::RFC::NULL, SAPNW::RFC::STRUCTURE, SAPNW::RFC::DECF16, SAPNW::RFC::DECF34, SAPNW::RFC::XMLDATA, SAPNW::RFC::STRING, SAPNW::RFC::XSTRING, SAPNW::RFC::EXCEPTION
                                else
                                  if parms[:type].class == SAPNW::RFC::Type
                                    parms[:typedef] = parms[:type]
                                                parms[:type] = parms[:typedef].type
                                                raise "Parameter type (#{self.class}) does not match Type type (#{parms[:typedef].inspect})\n" if self.class == SAPNW::RFC::Table and parms[:type] != SAPNW::RFC::TABLE
                            else            
                                    raise "Invalid SAPNW::RFC* type supplied (#{parms[:type]})\n"
                                        end
                        end
      funcdesc = nil
      len = 0
      ulen = 0
      decimals = 0
                        name = parms[:name]
                        type = parms[:type]
                        typedef = parms[:typedef] if parms.has_key?(:typedef)
                        len = parms[:len] if parms.has_key?(:len)
                        ulen = parms[:ulen] if parms.has_key?(:ulen)
                        decimals = parms[:decimals] if parms.has_key?(:decimals)
                else
                  raise "invalid parameters: #{parms.inspect}\n"
        end
  @function_descriptor = funcdesc
        @name = name
        @type = type
        @typedef = typedef
        @len = len
        @ulen = ulen
        @decimals = decimals
        @value = nil
        #$stderr.print "initilised parameter(#{@name}): #{self.inspect}\n"
end