Class: DbSchema::Definitions::Index
- Inherits:
-
Object
- Object
- DbSchema::Definitions::Index
- 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
Direct Known Subclasses
Defined Under Namespace
Classes: Column, Expression, TableField
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #btree? ⇒ Boolean
- #columns_to_sequel ⇒ Object
- #has_expressions? ⇒ Boolean
-
#initialize(name:, columns:, unique: false, type: :btree, condition: nil) ⇒ Index
constructor
A new instance of Index.
- #unique? ⇒ Boolean
- #with_name(new_name) ⇒ Object
Constructor Details
#initialize(name:, columns:, unique: false, type: :btree, condition: nil) ⇒ Index
Returns a new instance of Index.
7 8 9 10 11 12 13 |
# File 'lib/db_schema/definitions/index.rb', line 7 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
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
5 6 7 |
# File 'lib/db_schema/definitions/index.rb', line 5 def columns @columns end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
5 6 7 |
# File 'lib/db_schema/definitions/index.rb', line 5 def condition @condition end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/db_schema/definitions/index.rb', line 5 def name @name end |
#type ⇒ Object (readonly)
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
19 20 21 |
# File 'lib/db_schema/definitions/index.rb', line 19 def btree? type == :btree end |
#columns_to_sequel ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/db_schema/definitions/index.rb', line 23 def columns_to_sequel if btree? columns.map(&:ordered_expression) else columns.map(&:to_sequel) end end |
#has_expressions? ⇒ Boolean
31 32 33 |
# File 'lib/db_schema/definitions/index.rb', line 31 def has_expressions? !condition.nil? || columns.any?(&:expression?) end |
#unique? ⇒ Boolean
15 16 17 |
# File 'lib/db_schema/definitions/index.rb', line 15 def unique? @unique end |
#with_name(new_name) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/db_schema/definitions/index.rb', line 35 def with_name(new_name) Index.new( name: new_name, columns: columns, unique: unique?, type: type, condition: condition ) end |