Module: ActiveRecord::Materialized::ViewRefreshPolicyClassMethods::ClassMethods
- Extended by:
- T::Sig
- Defined in:
- lib/activerecord/materialized/view_refresh_policy_class_methods.rb
Overview
The refresh-policy DSL methods available on a ActiveRecord::Materialized::View subclass.
Instance Method Summary collapse
- #cold_read(strategy) ⇒ Object
- #max_staleness(duration = nil, &block) ⇒ Object
- #refresh_debounce(seconds) ⇒ Object
- #refresh_on_change(strategy = :async) ⇒ Object
- #resolved_cold_read_strategy ⇒ Object
- #resolved_max_staleness ⇒ Object
- #resolved_refresh_debounce ⇒ Object
- #resolved_refresh_strategy ⇒ Object
- #resolved_warm_up_queries ⇒ Object
- #view_class ⇒ Object
- #warm_up(&block) ⇒ Object
- #warm_up! ⇒ Object
Instance Method Details
#cold_read(strategy) ⇒ Object
37 38 39 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 37 def cold_read(strategy) @cold_read_strategy = T.let(strategy.to_sym, T.nilable(Symbol)) end |
#max_staleness(duration = nil, &block) ⇒ Object
91 92 93 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 91 def max_staleness(duration = nil, &block) @max_staleness_setting = T.let(duration || block, T.nilable(T.any(StalenessDuration, Proc))) end |
#refresh_debounce(seconds) ⇒ Object
32 33 34 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 32 def refresh_debounce(seconds) @refresh_debounce = T.let(seconds, T.nilable(DebounceInterval)) end |
#refresh_on_change(strategy = :async) ⇒ Object
27 28 29 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 27 def refresh_on_change(strategy = :async) @refresh_strategy = T.let(strategy.to_sym, T.nilable(Symbol)) end |
#resolved_cold_read_strategy ⇒ Object
42 43 44 45 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 42 def resolved_cold_read_strategy T.let(@cold_read_strategy, T.nilable(Symbol)) || ActiveRecord::Materialized.configuration.default_cold_read_strategy end |
#resolved_max_staleness ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 96 def resolved_max_staleness setting = @max_staleness_setting default = ActiveRecord::Materialized.configuration.default_max_staleness return T.cast(default, T.nilable(StalenessDuration)) if setting.nil? return T.unsafe(view_class).instance_eval(&setting) if setting.is_a?(Proc) setting end |
#resolved_refresh_debounce ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 76 def resolved_refresh_debounce interval = if @refresh_debounce.nil? ActiveRecord::Materialized.configuration.default_refresh_debounce else @refresh_debounce end interval.respond_to?(:to_f) ? interval.to_f : interval.to_i end |
#resolved_refresh_strategy ⇒ Object
71 72 73 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 71 def resolved_refresh_strategy @refresh_strategy || ActiveRecord::Materialized.configuration.default_refresh_strategy end |
#resolved_warm_up_queries ⇒ Object
55 56 57 58 59 60 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 55 def resolved_warm_up_queries block = T.let(@warm_up_definition, T.nilable(Proc)) return [] if block.nil? Kernel.Array(T.unsafe(view_class).instance_eval(&block)) end |
#view_class ⇒ Object
22 23 24 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 22 def view_class T.cast(self, T.class_of(View)) end |
#warm_up(&block) ⇒ Object
50 51 52 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 50 def warm_up(&block) @warm_up_definition = T.let(block, T.nilable(Proc)) end |
#warm_up! ⇒ Object
65 66 67 68 |
# File 'lib/activerecord/materialized/view_refresh_policy_class_methods.rb', line 65 def warm_up! resolved_warm_up_queries.each(&:to_a) view_class.refresh! end |