Module: ODPI::Object

Defined in:
lib/odpi/object.rb

Defined Under Namespace

Modules: NamedCollection Classes: Base

Constant Summary collapse

@@oracle_type_to_ruby_class =
{}
@@ruby_class_to_oracle_type =
{}

Class Method Summary collapse

Class Method Details

.find_class(schema, name) ⇒ Object


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/odpi/object.rb', line 60

def self.find_class(schema, name)
  fullname = "#{schema}.#{name}"
  klass = @@oracle_type_to_ruby_class[fullname]
  klass = @@oracle_type_to_ruby_class[name] if klass.nil?
  if klass.nil?
    module_name = oracle_name_to_ruby_constant_name(schema)
    class_name = oracle_name_to_ruby_constant_name(name)

    if self.const_defined?(module_name, false)
      mod = self.const_get(module_name, false)
    else
      mod = self.const_set(module_name, Module.new)
    end

    if mod.const_defined?(class_name, false)
      klass = mod.const_get(class_name, false)
    else
      klass = mod.const_set(class_name, Class.new(Base))
    end
    @@oracle_type_to_ruby_class[fullname] = klass
    @@ruby_class_to_oracle_type[klass] = fullname
  end
  klass
end

.find_name_by_class(klass) ⇒ Object


85
86
87
# File 'lib/odpi/object.rb', line 85

def self.find_name_by_class(klass)
  @@ruby_class_to_oracle_type[klass]
end

.oracle_name_to_ruby_constant_name(name) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/odpi/object.rb', line 39

def self.oracle_name_to_ruby_constant_name(name)
  name = if name !~ /[[:lower:]]/
           name.downcase.gsub(/(^|_)([[:lower:]])/) { $2.upcase }
         else
           name.sub(/^([a-z])/) { $1.upcase }
         end.gsub(/[$#]/, '_')
  if name =~ /^[A-Z]/
    name
  else
    'C' + name
  end
end

.oracle_name_to_ruby_identifier_name(name) ⇒ Object


52
53
54
55
56
57
58
# File 'lib/odpi/object.rb', line 52

def self.oracle_name_to_ruby_identifier_name(name)
  if name !~ /[[:lower:]]/
    name.downcase
  else
    name.sub(/^([a-z])/) { $1.downcase }
  end.gsub(/[$#]/, '_')
end

.set_typename(klass, name) ⇒ Object


89
90
91
92
# File 'lib/odpi/object.rb', line 89

def self.set_typename(klass, name)
  @@ruby_class_to_oracle_type[klass] = name
  @@oracle_type_to_ruby_class[name] = klass
end