Class: ActiveRecord::Materialized::ColdRead

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/activerecord/materialized/cold_read.rb

Overview

The relation a read is served from when a view is not yet materialized, per its cold_read strategy. Read-through wraps the live source as a derived table aliased to the cache table name, so where/order/limit/count keep working against the same column names.

Instance Method Summary collapse

Constructor Details

#initialize(view_class) ⇒ ColdRead

Returns a new instance of ColdRead.



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

def initialize(view_class)
  @view_class = view_class
end

Instance Method Details

#scopeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/activerecord/materialized/cold_read.rb', line 19

def scope
  case @view_class.resolved_cold_read_strategy
  when :read_through
    ensure_skeleton!
    unscoped.from(source_derived_table)
  when :serve_stale
    ensure_skeleton!
    unscoped
  when :raise
    Kernel.raise NotMaterializedError, not_materialized_message
  else
    Kernel.raise ArgumentError, "Unknown cold_read strategy: #{@view_class.resolved_cold_read_strategy}"
  end
end