Class: PgObjects::DbObject

Inherits:
Object
  • Object
show all
Includes:
Memery
Defined in:
lib/pg_objects/db_object.rb

Overview

Represents DB object as it is described in file

[name] name of file without extension [full_name] full pathname of file [object_name] name of function, trigger etc. if it was successfully parsed, otherwise - nil [qualified_object_name] schema-qualified object name (+schema.name+) when a schema is present, otherwise same as object_name; nil if parsing failed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, status = :new, parser:) ⇒ DbObject

Returns a new instance of DbObject.



19
20
21
22
23
# File 'lib/pg_objects/db_object.rb', line 19

def initialize(path, status = :new, parser:)
  @full_name = path
  @status = status
  @parser = parser
end

Instance Attribute Details

#full_nameObject (readonly)

Returns the value of attribute full_name.



17
18
19
# File 'lib/pg_objects/db_object.rb', line 17

def full_name
  @full_name
end

#object_nameObject (readonly)

Returns the value of attribute object_name.



17
18
19
# File 'lib/pg_objects/db_object.rb', line 17

def object_name
  @object_name
end

#qualified_object_nameObject (readonly)

Returns the value of attribute qualified_object_name.



17
18
19
# File 'lib/pg_objects/db_object.rb', line 17

def qualified_object_name
  @qualified_object_name
end

#statusObject

Returns the value of attribute status.



16
17
18
# File 'lib/pg_objects/db_object.rb', line 16

def status
  @status
end

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
# File 'lib/pg_objects/db_object.rb', line 25

def create
  parser.load(sql_query)
  @object_name = parser.fetch_object_name
  @qualified_object_name = parser.fetch_qualified_object_name
  @status = :pending

  self
end

#dependenciesObject



40
41
42
# File 'lib/pg_objects/db_object.rb', line 40

def dependencies
  parser.fetch_directives[:depends_on]
end

#nameObject



35
36
37
# File 'lib/pg_objects/db_object.rb', line 35

def name
  File.basename(full_name, '.*')
end

#sql_queryObject



45
46
47
# File 'lib/pg_objects/db_object.rb', line 45

def sql_query
  File.read(full_name)
end