Class: Oraora::Meta::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/oraora/meta/object.rb

Direct Known Subclasses

MaterializedView, Sequence, Table, View

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, name, type = nil) ⇒ Object

Returns a new instance of Object.



6
7
8
9
10
# File 'lib/oraora/meta/object.rb', line 6

def initialize(schema, name, type = nil)
  @schema = schema
  @name = name
  @type = type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/oraora/meta/object.rb', line 4

def type
  @type
end

Class Method Details

.from_oci(oci, schema, name, type = nil) ⇒ Object



29
30
31
# File 'lib/oraora/meta/object.rb', line 29

def self.from_oci(oci, schema, name, type = nil)
  new(schema, name, type).load_from_oci(oci)
end

Instance Method Details

#describe(options = {}) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/oraora/meta/object.rb', line 33

def describe(options = {})
  "    Object \#{@schema}.\#{@name}\n    Id:           \#{@id}\n    Type:         \#{@type}\n  HERE\nend\n".reset_indentation

#list(options = {}, filter = nil) ⇒ Object

Raises:



41
42
43
# File 'lib/oraora/meta/object.rb', line 41

def list(options = {}, filter = nil)
  raise NotApplicable, "Cannot list for this object"
end

#load_from_oci(oci) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/oraora/meta/object.rb', line 12

def load_from_oci(oci)
  if !@type
    @id, @type = oci.select_one("SELECT object_id, object_type FROM all_objects
                                  WHERE owner = :schema AND object_name = :name
                                  ORDER BY decode(namespace,  19, 0,  99)", @schema, @name) if !@type
    raise NotExists if !@id
    @id = @id.to_i
  end
  case @type
    when 'TABLE'              then Table.from_oci(oci, @schema, @name)
    when 'VIEW'               then View.from_oci(oci, @schema, @name)
    when 'MATERIALIZED VIEW'  then MaterializedView.from_oci(oci, @schema, @name)
    when 'SEQUENCE'           then Sequence.from_oci(oci, @schema, @name)
    else self
  end
end