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
Returns a new instance of Index.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 14 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.
11 12 13 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 11 def columns @columns end |
#interleave_in ⇒ Object
Returns the value of attribute interleave_in.
11 12 13 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 11 def interleave_in @interleave_in end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 11 def name @name end |
#null_filtered ⇒ Object
Returns the value of attribute null_filtered.
11 12 13 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 11 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.
11 12 13 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 11 def state @state end |
#storing ⇒ Object
Returns the value of attribute storing.
11 12 13 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 11 def storing @storing end |
#table ⇒ Object
Returns the value of attribute table.
11 12 13 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 11 def table @table end |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 11 def type @type end |
#unique ⇒ Object
Returns the value of attribute unique.
11 12 13 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 11 def unique @unique end |
Instance Method Details
#column_names ⇒ Object
47 48 49 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 47 def column_names columns_by_position.map(&:name) end |
#columns_by_position ⇒ Object
41 42 43 44 45 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 41 def columns_by_position @columns.select(&:ordinal_position).sort do |c1, c2| c1.ordinal_position <=> c2.ordinal_position end end |
#options ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 57 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
51 52 53 54 55 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 51 def orders columns_by_position.each_with_object({}) do |c, r| r[c.name] = c.desc? ? :desc : :asc end end |
#primary? ⇒ Boolean
37 38 39 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 37 def primary? @type == "PRIMARY_KEY" end |
#rename_column_options(old_column, new_column) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/activerecord_spanner_adapter/index.rb', line 68 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 |