Module: ActiveRecord::PLSQL::Pipelined::ClassMethods

Defined in:
lib/active_record/plsql/pipelined.rb

Instance Method Summary collapse

Instance Method Details

#arel_tableObject



68
69
70
71
72
73
74
# File 'lib/active_record/plsql/pipelined.rb', line 68

def arel_table
  if pipelined?
    @arel_table ||= Arel::Table.new(table_name_with_arguments, engine: arel_engine, as: pipelined_function_alias)
  else
    super
  end
end

#pipelined_argumentsObject



18
19
20
21
# File 'lib/active_record/plsql/pipelined.rb', line 18

def pipelined_arguments
  raise PipelinedFunctionError, "Pipelined function didn't set" unless pipelined?
  @pipelined_arguments ||= get_pipelined_arguments
end

#pipelined_arguments_namesObject



23
24
25
# File 'lib/active_record/plsql/pipelined.rb', line 23

def pipelined_arguments_names
  pipelined_arguments.map(&:name)
end

#pipelined_functionObject Also known as: pipelined?



27
28
29
# File 'lib/active_record/plsql/pipelined.rb', line 27

def pipelined_function
  @pipelined_function
end

#pipelined_function=(function) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/active_record/plsql/pipelined.rb', line 33

def pipelined_function=(function)
  case function
  when String, Symbol
    # Name without schema expected
    function_name = function.to_s.split('.').map(&:downcase).map(&:to_sym)
    case function_name.size
    when 2
      pipelined_function = plsql.send(function_name.first)[function_name.second]
    when 1
      pipelined_function = PLSQL::PipelinedFunction.find(plsql, function_name.first)
    else
      raise ArgumentError, 'Setting schema via string not supported yed'
    end
    raise ArgumentError, 'Pipelined function not found by string: %s' % function unless pipelined_function
  when ::PLSQL::PipelinedFunction, nil
    pipelined_function = function
  else
    raise ArgumentError, 'Unsupported type of pipelined function: %s' % function.inspect
  end

  if pipelined_function && pipelined_function.overloaded?
    raise ArgumentError, 'Overloaded functions are not supported yet'
  end

  @pipelined_function = pipelined_function
  @pipelined_arguments = nil
  @table_name = pipelined_function_name if @pipelined_function
end

#pipelined_function_aliasObject



76
77
78
79
# File 'lib/active_record/plsql/pipelined.rb', line 76

def pipelined_function_alias
  # GET_USER_BY_NAME => GUBN
  @pipelined_function.procedure.scan(/^\w|_\w/).join('').gsub('_', '')
end

#pipelined_function_nameObject



62
63
64
65
66
# File 'lib/active_record/plsql/pipelined.rb', line 62

def pipelined_function_name
  return @full_function_name if defined? @full_function_name
  package_name, function_name = @pipelined_function.package, @pipelined_function.procedure
  @full_function_name = [package_name, function_name].compact.join('.')
end

#table_exist?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/active_record/plsql/pipelined.rb', line 87

def table_exist?
  pipelined? || super
end

#table_name_with_argumentsObject



81
82
83
84
85
# File 'lib/active_record/plsql/pipelined.rb', line 81

def table_name_with_arguments
  @table_name_with_arguments ||= PipelinedFunctionTableName.new(
      "TABLE(%s(%s))" % [table_name, pipelined_arguments.map{|a| ":#{a.name}"}.join(',')]
  )
end