Class: DbSchema::Definitions::Index
- Inherits:
-
Object
- Object
- DbSchema::Definitions::Index
show all
- Defined in:
- lib/db_schema/definitions/index.rb,
lib/db_schema/definitions/index/column.rb,
lib/db_schema/definitions/index/expression.rb,
lib/db_schema/definitions/index/table_field.rb
Defined Under Namespace
Classes: Column, Expression, TableField
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name:, columns:, primary: false, unique: false, type: :btree, condition: nil) ⇒ Index
Returns a new instance of Index.
7
8
9
10
11
12
13
14
|
# File 'lib/db_schema/definitions/index.rb', line 7
def initialize(name:, columns:, primary: false, unique: false, type: :btree, condition: nil)
@name = name.to_sym
@columns = columns
@primary = primary
@unique = unique
@type = type
@condition = condition
end
|
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
5
6
7
|
# File 'lib/db_schema/definitions/index.rb', line 5
def columns
@columns
end
|
#condition ⇒ Object
Returns the value of attribute condition.
5
6
7
|
# File 'lib/db_schema/definitions/index.rb', line 5
def condition
@condition
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/db_schema/definitions/index.rb', line 5
def name
@name
end
|
#type ⇒ Object
Returns the value of attribute type.
5
6
7
|
# File 'lib/db_schema/definitions/index.rb', line 5
def type
@type
end
|
Instance Method Details
#btree? ⇒ Boolean
24
25
26
|
# File 'lib/db_schema/definitions/index.rb', line 24
def btree?
type == :btree
end
|
#columns_to_sequel ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/db_schema/definitions/index.rb', line 28
def columns_to_sequel
if btree?
columns.map(&:ordered_expression)
else
columns.map(&:to_sequel)
end
end
|
#has_expressions? ⇒ Boolean
36
37
38
|
# File 'lib/db_schema/definitions/index.rb', line 36
def has_expressions?
!condition.nil? || columns.any?(&:expression?)
end
|
#primary? ⇒ Boolean
16
17
18
|
# File 'lib/db_schema/definitions/index.rb', line 16
def primary?
@primary
end
|
#unique? ⇒ Boolean
20
21
22
|
# File 'lib/db_schema/definitions/index.rb', line 20
def unique?
@unique
end
|
#with_condition(new_condition) ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/db_schema/definitions/index.rb', line 51
def with_condition(new_condition)
Index.new(
name: name,
columns: columns,
primary: primary?,
unique: unique?,
type: type,
condition: new_condition
)
end
|
#with_name(new_name) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/db_schema/definitions/index.rb', line 40
def with_name(new_name)
Index.new(
name: new_name,
columns: columns,
primary: primary?,
unique: unique?,
type: type,
condition: condition
)
end
|