Class: Arel::Nodes::ValuesTable
- Inherits:
-
Node
- Object
- Node
- Arel::Nodes::ValuesTable
- Defined in:
- lib/activerecord-updateinbulk/arel/nodes/values_table.rb
Overview
Represents the VALUES table constructor as an Arel node. Mirrors Arel::Table behavior by requiring a name at construction time. Column names are also required because adapter defaults vary; prefer using the default names from connection.values_table_default_column_names(width) to keep the generated query simple.
This is a private class that may be used by typecasting logic in custom adapters.
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#name ⇒ Object
(also: #table_alias)
readonly
Returns the value of attribute name.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #[](name, table = self) ⇒ Object
- #alias(table = name) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #from(table = name) ⇒ Object
- #hash ⇒ Object
-
#initialize(name, rows, columns) ⇒ ValuesTable
constructor
name- The table name (required to mirror Arel::Table). - #to_cte ⇒ Object
Constructor Details
#initialize(name, rows, columns) ⇒ ValuesTable
name - The table name (required to mirror Arel::Table). rows - An array of arrays; each inner array is one row of values. columns - An array of column name strings, typically from
<tt>connection.values_table_default_column_names(width)</tt>.
20 21 22 23 24 25 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 20 def initialize(name, rows, columns) @name = name.to_s @width = rows.first.size @rows = rows @columns = columns.map(&:to_s) end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
13 14 15 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 13 def columns @columns end |
#name ⇒ Object (readonly) Also known as: table_alias
Returns the value of attribute name.
13 14 15 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 13 def name @name end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
13 14 15 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 13 def rows @rows end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
13 14 15 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 13 def width @width end |
Instance Method Details
#[](name, table = self) ⇒ Object
27 28 29 30 31 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 27 def [](name, table = self) name = columns[name] if name.is_a?(Integer) name = name.name if name.is_a?(Symbol) Arel::Attribute.new(table, name) end |
#alias(table = name) ⇒ Object
37 38 39 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 37 def alias(table = name) Arel::Nodes::TableAlias.new(grouping(self), table) end |
#eql?(other) ⇒ Boolean Also known as: ==
49 50 51 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 49 def eql?(other) @name == other.name && @rows == other.rows && @columns == other.columns end |
#from(table = name) ⇒ Object
33 34 35 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 33 def from(table = name) Arel::SelectManager.new(table ? self.alias(table) : grouping(self)) end |
#hash ⇒ Object
45 46 47 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 45 def hash [@name, @rows, @columns].hash end |
#to_cte ⇒ Object
41 42 43 |
# File 'lib/activerecord-updateinbulk/arel/nodes/values_table.rb', line 41 def to_cte self.alias.to_cte end |