Class: Baza::Driver::Pg::Index

Inherits:
Index
  • Object
show all
Defined in:
lib/baza/driver/pg/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Index

#data, #inspect, #to_param, #to_s

Methods included from Baza::DatabaseModelFunctionality

#model_name, #to_model

Constructor Details

#initialize(args) ⇒ Index

Returns a new instance of Index.



4
5
6
7
8
# File 'lib/baza/driver/pg/index.rb', line 4

def initialize(args)
  @db = args.fetch(:db)
  @data = args.fetch(:data)
  @name = @data.fetch(:indexname)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/baza/driver/pg/index.rb', line 2

def name
  @name
end

Instance Method Details

#columnsObject



32
33
34
# File 'lib/baza/driver/pg/index.rb', line 32

def columns
  @data.fetch(:indexdef).match(/\((.+)\)\Z/)[1].split(/\s*,\s/)
end

#primary?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/baza/driver/pg/index.rb', line 22

def primary?
  name == "#{table_name}_pkey"
end

#rename(new_name) ⇒ Object



26
27
28
29
30
# File 'lib/baza/driver/pg/index.rb', line 26

def rename(new_name)
  @db.query("ALTER INDEX #{@db.sep_index}#{@db.escape_index(name)}#{@db.sep_index} RENAME TO #{@db.sep_index}#{@db.escape_index(new_name)}#{@db.sep_index}")
  @name = new_name.to_s
  self
end

#tableObject



10
11
12
# File 'lib/baza/driver/pg/index.rb', line 10

def table
  @db.tables[table_name]
end

#table_nameObject



14
15
16
# File 'lib/baza/driver/pg/index.rb', line 14

def table_name
  @data.fetch(:tablename)
end

#unique?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/baza/driver/pg/index.rb', line 18

def unique?
  @data.fetch(:indexdef).include?(" UNIQUE ")
end