Class: ActiveRecord::Materialized::CacheTableSchema::ColumnDefinition Private

Inherits:
Data
  • Object
show all
Defined in:
lib/activerecord/materialized/cache_table_schema.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

An inferred cache-table column: name from the relation projection, a create_table column type, and — for a :decimal — the precision/scale that preserve value fidelity (a bare decimal is DECIMAL(10,0) on MySQL, which truncates).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, precision: nil, scale: nil) ⇒ ColumnDefinition

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ColumnDefinition.



15
# File 'lib/activerecord/materialized/cache_table_schema.rb', line 15

def initialize(name:, type:, precision: nil, scale: nil) = super

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



14
15
16
# File 'lib/activerecord/materialized/cache_table_schema.rb', line 14

def name
  @name
end

#precisionObject (readonly)

Returns the value of attribute precision

Returns:

  • (Object)

    the current value of precision



14
15
16
# File 'lib/activerecord/materialized/cache_table_schema.rb', line 14

def precision
  @precision
end

#scaleObject (readonly)

Returns the value of attribute scale

Returns:

  • (Object)

    the current value of scale



14
15
16
# File 'lib/activerecord/materialized/cache_table_schema.rb', line 14

def scale
  @scale
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



14
15
16
# File 'lib/activerecord/materialized/cache_table_schema.rb', line 14

def type
  @type
end

Instance Method Details

#migration_argumentsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The trailing arguments for a t.<type> :<name> migration line ("" when none).



23
24
25
# File 'lib/activerecord/materialized/cache_table_schema.rb', line 23

def migration_arguments
  options.map { |key, value| ", #{key}: #{value}" }.join
end

#optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

create_table options for this column (precision/scale for a decimal; none otherwise).



18
19
20
# File 'lib/activerecord/materialized/cache_table_schema.rb', line 18

def options
  { precision: precision, scale: scale }.compact
end