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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of DbObject.



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

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.



13
14
15
# File 'lib/pg_objects/db_object.rb', line 13

def full_name
  @full_name
end

#object_nameObject (readonly)

Returns the value of attribute object_name.



13
14
15
# File 'lib/pg_objects/db_object.rb', line 13

def object_name
  @object_name
end

#statusObject

Returns the value of attribute status.



12
13
14
# File 'lib/pg_objects/db_object.rb', line 12

def status
  @status
end

Instance Method Details

#createObject



21
22
23
24
25
26
27
# File 'lib/pg_objects/db_object.rb', line 21

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

  self
end

#dependenciesObject



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

def dependencies
  parser.fetch_directives[:depends_on]
end

#nameObject



30
31
32
# File 'lib/pg_objects/db_object.rb', line 30

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

#sql_queryObject



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

def sql_query
  File.read(full_name)
end