Class: KnjDB_mysql::Indexes::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Index

Returns a new instance of Index.



10
11
12
13
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 10

def initialize(args)
  @args = args
  @columns = []
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



8
9
10
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 8

def columns
  @columns
end

Instance Method Details

#dataObject



28
29
30
31
32
33
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 28

def data
  return {
    "name" => name,
    "columns" => @columns
  }
end

#dropObject



23
24
25
26
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 23

def drop
  sql = "DROP INDEX `#{self.name}` ON `#{self.table.name}`"
  @args[:db].query(sql)
end

#nameObject



15
16
17
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 15

def name
  return @args[:data][:Key_name]
end

#tableObject



19
20
21
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 19

def table
  return @args[:db].tables[@args[:table_name]]
end

#to_sObject

Inspect crashes if this is not present? - knj.



45
46
47
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 45

def to_s
  return "#<#{self.class.name}>"
end

#unique?Boolean

Returns true if the index is a unique-index.

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 36

def unique?
  if @args[:data][:Index_type] == "UNIQUE"
    return true
  else
    return false
  end
end