Class: ActiveRecordSpannerAdapter::Index
- Inherits:
-
Object
- Object
- ActiveRecordSpannerAdapter::Index
- Defined in:
- lib/activerecord_spanner_adapter/index.rb,
lib/activerecord_spanner_adapter/index/column.rb
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#interleave_in ⇒ Object
Returns the value of attribute interleave_in.
-
#name ⇒ Object
Returns the value of attribute name.
-
#null_filtered ⇒ Object
Returns the value of attribute null_filtered.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#state ⇒ Object
Returns the value of attribute state.
-
#storing ⇒ Object
Returns the value of attribute storing.
-
#table ⇒ Object
Returns the value of attribute table.
-
#type ⇒ Object
Returns the value of attribute type.
-
#unique ⇒ Object
Returns the value of attribute unique.
Instance Method Summary collapse
- #column_names ⇒ Object
- #columns_by_position ⇒ Object
-
#initialize(table, name, columns, type: nil, unique: false, null_filtered: false, interleave_in: nil, storing: nil, state: nil, schema: "") ⇒ Index
constructor
A new instance of Index.
- #options ⇒ Object
- #orders ⇒ Object
- #primary? ⇒ Boolean
- #rename_column_options(old_column, new_column) ⇒ Object
Constructor Details
#initialize(table, name, columns, type: nil, unique: false, null_filtered: false, interleave_in: nil, storing: nil, state: nil, schema: "") ⇒ Index
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 22 def initialize \ table, name, columns, type: nil, unique: false, null_filtered: false, interleave_in: nil, storing: nil, state: nil, schema: "" @schema = schema.to_s @table = table.to_s @name = name.to_s @columns = Array(columns) @type = type @unique = unique @null_filtered = null_filtered @interleave_in = interleave_in unless interleave_in.to_s.empty? @storing = storing || [] @state = state end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
14 15 16 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 14 def columns @columns end |
#interleave_in ⇒ Object
Returns the value of attribute interleave_in.
18 19 20 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 18 def interleave_in @interleave_in end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 13 def name @name end |
#null_filtered ⇒ Object
Returns the value of attribute null_filtered.
17 18 19 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 17 def null_filtered @null_filtered end |
#schema ⇒ Object
Returns the value of attribute schema.
11 12 13 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 11 def schema @schema end |
#state ⇒ Object
Returns the value of attribute state.
20 21 22 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 20 def state @state end |
#storing ⇒ Object
Returns the value of attribute storing.
19 20 21 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 19 def storing @storing end |
#table ⇒ Object
Returns the value of attribute table.
12 13 14 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 12 def table @table end |
#type ⇒ Object
Returns the value of attribute type.
15 16 17 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 15 def type @type end |
#unique ⇒ Object
Returns the value of attribute unique.
16 17 18 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 16 def unique @unique end |
Instance Method Details
#column_names ⇒ Object
55 56 57 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 55 def column_names columns_by_position.map(&:name) end |
#columns_by_position ⇒ Object
49 50 51 52 53 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 49 def columns_by_position @columns.select(&:ordinal_position).sort do |c1, c2| c1.ordinal_position <=> c2.ordinal_position end end |
#options ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 65 def { name: name, order: orders, unique: unique, interleave_in: interleave_in, null_filtered: null_filtered, storing: storing }.delete_if { |_, v| v.nil? } end |
#orders ⇒ Object
59 60 61 62 63 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 59 def orders columns_by_position.each_with_object({}) do |c, r| r[c.name] = c.desc? ? :desc : :asc end end |
#primary? ⇒ Boolean
45 46 47 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 45 def primary? @type == "PRIMARY_KEY" end |
#rename_column_options(old_column, new_column) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 76 def old_column, new_column opts = opts[:order].transform_keys do |key| key.to_s == new_column.to_s end columns = column_names.map do |c| c.to_s == old_column.to_s ? new_column : c end { options: opts, columns: columns } end |