Class: DbSchema::Definitions::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/db_schema/definitions.rb

Direct Known Subclasses

Changes::CreateIndex

Defined Under Namespace

Classes: Column, Expression, TableField

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, columns:, unique: false, type: :btree, condition: nil) ⇒ Index

Returns a new instance of Index.



9
10
11
12
13
14
15
# File 'lib/db_schema/definitions.rb', line 9

def initialize(name:, columns:, unique: false, type: :btree, condition: nil)
  @name      = name.to_sym
  @columns   = columns
  @unique    = unique
  @type      = type
  @condition = condition
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



7
8
9
# File 'lib/db_schema/definitions.rb', line 7

def columns
  @columns
end

#conditionObject (readonly)

Returns the value of attribute condition.



7
8
9
# File 'lib/db_schema/definitions.rb', line 7

def condition
  @condition
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/db_schema/definitions.rb', line 7

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/db_schema/definitions.rb', line 7

def type
  @type
end

Instance Method Details

#btree?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/db_schema/definitions.rb', line 21

def btree?
  type == :btree
end

#columns_to_sequelObject



25
26
27
28
29
30
31
# File 'lib/db_schema/definitions.rb', line 25

def columns_to_sequel
  if btree?
    columns.map(&:ordered_expression)
  else
    columns.map(&:to_sequel)
  end
end

#unique?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/db_schema/definitions.rb', line 17

def unique?
  @unique
end