Class: PLSQL::Type::TypeProcedure

Inherits:
Object
  • Object
show all
Includes:
ProcedureCommon
Defined in:
lib/plsql/type.rb

Overview

wrapper class to simulate Procedure class for ProcedureClass#exec

Constant Summary

Constants included from ProcedureCommon

ProcedureCommon::PLSQL_COLLECTION_TYPES, ProcedureCommon::PLSQL_COMPOSITE_TYPES

Instance Attribute Summary collapse

Attributes included from ProcedureCommon

#package, #procedure, #return, #schema, #schema_name

Instance Method Summary collapse

Methods included from ProcedureCommon

#collection_type?, #composite_type?, #construct_argument_list_for_overloads, #ensure_tmp_tables_created, #get_argument_metadata, #overloaded?, type_to_sql

Constructor Details

#initialize(schema, type, procedure) ⇒ TypeProcedure

Returns a new instance of TypeProcedure.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/plsql/type.rb', line 141

def initialize(schema, type, procedure)
  @schema = schema
  @type = type
  @schema_name = @type.schema_name
  @type_name = @type.type_name
  @object_id = @type.type_object_id

  # if default constructor
  if @default_constructor = (procedure == :new)
    @procedure = @type.collection? ? nil : @type_name
    set_default_constructor_arguments
  # if defined type procedure
  else
    @procedure = procedure.to_s.upcase
    
    # add also definition for default constructor in case of custom constructor
    set_default_constructor_arguments if @procedure == @type_name
  end

  # constructors do not need type prefix in call
  @package = @procedure == @type_name ? nil : @type_name
end

Instance Attribute Details

#argument_listObject (readonly)

Returns the value of attribute argument_list.



169
170
171
# File 'lib/plsql/type.rb', line 169

def argument_list
  @argument_list
end

#argumentsObject (readonly)

Returns the value of attribute arguments.



169
170
171
# File 'lib/plsql/type.rb', line 169

def arguments
  @arguments
end

#out_listObject (readonly)

Returns the value of attribute out_list.



169
170
171
# File 'lib/plsql/type.rb', line 169

def out_list
  @out_list
end

Instance Method Details

#argument_list_without_selfObject



180
181
182
183
184
185
186
187
188
# File 'lib/plsql/type.rb', line 180

def argument_list_without_self
  @argument_list_without_self ||= begin
    hash = {}
    @argument_list.each do |ov, arg_list|
      hash[ov] = arg_list.select{|arg| arg != :self}
    end
    hash
  end
end

#arguments_without_selfObject



170
171
172
173
174
175
176
177
178
# File 'lib/plsql/type.rb', line 170

def arguments_without_self
  @arguments_without_self ||= begin
    hash = {}
    @arguments.each do |ov, args|
      hash[ov] = args.reject{|key, value| key == :self}
    end
    hash
  end
end

#call_sql(params_string) ⇒ Object

will be called for collection constructor



165
166
167
# File 'lib/plsql/type.rb', line 165

def call_sql(params_string)
  "#{params_string};\n"
end

#exec_with_options(args, options = {}, &block) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
# File 'lib/plsql/type.rb', line 200

def exec_with_options(args, options={}, &block)
  call = ProcedureCall.new(self, args, options)
  result = call.exec(&block)
  # if procedure was called then modified object is returned in SELF output parameter
  if result.is_a?(Hash) && result[:self]
    object = result.delete(:self)
    result.empty? ? object : [object, result]
  else
    result
  end
end

#out_list_without_selfObject



190
191
192
193
194
195
196
197
198
# File 'lib/plsql/type.rb', line 190

def out_list_without_self
  @out_list_without_self ||= begin
    hash = {}
    @out_list.each do |ov, out_list|
      hash[ov] = out_list.select{|arg| arg != :self}
    end
    hash
  end
end