Class: Avmtrf1::Oracle::Objects

Inherits:
Object
  • Object
show all
Defined in:
lib/avmtrf1/oracle/objects.rb,
lib/avmtrf1/oracle/objects/relation.rb,
lib/avmtrf1/oracle/objects/sql_builder.rb

Defined Under Namespace

Classes: Relation, SqlBuilder

Constant Summary collapse

COLUMNS_TO_ATTRIBUTES =
{
  object_id: :id,
  object_name: :name,
  object_type: :type,
  owner: :owner
}.freeze
TABLE_NAME =
'all_objects'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.row_to_attributes(row) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/avmtrf1/oracle/objects.rb', line 26

def row_to_attributes(row)
  return nil if row.blank?

  COLUMNS_TO_ATTRIBUTES.map do |column, attribute|
    [attribute, row.fetch(column.to_s.upcase)]
  end.to_h
end

.row_to_object(connection, row) ⇒ Object



19
20
21
22
23
24
# File 'lib/avmtrf1/oracle/objects.rb', line 19

def row_to_object(connection, row)
  ::Avmtrf1::Oracle::Object.factory_get(
    connection,
    row_to_attributes(row)
  )
end

Instance Method Details

#first(options = {}) ⇒ Object



41
42
43
44
45
46
# File 'lib/avmtrf1/oracle/objects.rb', line 41

def first(options = {})
  self.class.row_to_object(
    connection,
    connection.first_row_hash(sql(options))
  )
end

#list(options = {}) ⇒ Object



37
38
39
# File 'lib/avmtrf1/oracle/objects.rb', line 37

def list(options = {})
  ::Avmtrf1::Oracle::Objects::Relation.new(connection, sql(options))
end

#sql(options) ⇒ Object



48
49
50
# File 'lib/avmtrf1/oracle/objects.rb', line 48

def sql(options)
  ::Avmtrf1::Oracle::Objects::SqlBuilder.new(options).sql
end