Module: ActiveRecord::Materialized::ViewConfigurationClassMethods::ClassMethods
- Includes:
- ActiveRecord::Materialized::ViewIncrementalClassMethods::ClassMethods, ActiveRecord::Materialized::ViewRefreshPolicyClassMethods::ClassMethods
- Defined in:
- lib/activerecord/materialized/view_configuration_class_methods.rb
Overview
The configuration DSL methods available on a ActiveRecord::Materialized::View subclass.
Constant Summary collapse
- NIL_RESET_IVARS =
Per-subclass DSL ivars reset to nil on inheritance so a subclass never inherits another view's configuration. (
@dependency_tablesresets to an empty list instead — see #inherited.) %i[ @refresh_strategy @refresh_debounce @refresh_mode @incremental_source_definition @incremental_key_columns @partition_key_resolvers @cold_read_strategy @change_source @warm_up_definition ].freeze
Instance Method Summary collapse
-
#depends_on(*tables) ⇒ void
Declares the dependency tables whose committed writes trigger maintenance of this view.
- #inherited(subclass) ⇒ Object
-
#materialized_from(&block) ⇒ void
Declares the source relation this view materializes and registers the view unless it is abstract.
- #metadata ⇒ Object
- #resolved_source ⇒ Object
- #view_class ⇒ Object
- #view_key ⇒ Object
Methods included from ActiveRecord::Materialized::ViewRefreshPolicyClassMethods::ClassMethods
#change_source, #cold_read, #max_staleness, #refresh_debounce, #refresh_on_change, #resolved_change_source, #resolved_cold_read_strategy, #resolved_max_staleness, #resolved_refresh_debounce, #resolved_refresh_strategy, #resolved_warm_up_queries, #warm_up, #warm_up!
Methods included from ActiveRecord::Materialized::ViewIncrementalClassMethods::ClassMethods
#aggregate_analysis, #delta_maintaining?, #incremental_from, #incremental_key_columns, #incremental_keys, #incremental_source_override?, #incrementally_maintainable?, #maintenance_key_columns, #partition_key_for, #partition_key_resolver_for, #partition_key_resolvers, #record_write_change!, #refresh_mode, #resolved_incremental_source, #resolved_refresh_mode, #view_definition
Instance Method Details
#depends_on(*tables) ⇒ void
This method returns an undefined value.
Declares the dependency tables whose committed writes trigger maintenance of this view.
55 56 57 |
# File 'lib/activerecord/materialized/view_configuration_class_methods.rb', line 55 def depends_on(*tables) DependencyRegistry.register(view_class, tables) end |
#inherited(subclass) ⇒ Object
29 30 31 32 33 |
# File 'lib/activerecord/materialized/view_configuration_class_methods.rb', line 29 def inherited(subclass) super subclass.instance_variable_set(:@dependency_tables, []) NIL_RESET_IVARS.each { |ivar| subclass.instance_variable_set(ivar, nil) } end |
#materialized_from(&block) ⇒ void
This method returns an undefined value.
Declares the source relation this view materializes and registers the view unless it is abstract.
46 47 48 49 |
# File 'lib/activerecord/materialized/view_configuration_class_methods.rb', line 46 def materialized_from(&block) @source_definition = block Registry.register(view_class) unless view_class.abstract_class? end |
#metadata ⇒ Object
66 67 68 |
# File 'lib/activerecord/materialized/view_configuration_class_methods.rb', line 66 def @metadata ||= ActiveRecord::Materialized::Metadata.new(view_class) end |
#resolved_source ⇒ Object
59 60 61 62 63 64 |
# File 'lib/activerecord/materialized/view_configuration_class_methods.rb', line 59 def resolved_source resolve_source_definition( @source_definition, "materialized_from is required for #{view_class.name || view_class.view_key}" ) end |
#view_class ⇒ Object
25 26 27 |
# File 'lib/activerecord/materialized/view_configuration_class_methods.rb', line 25 def view_class self end |
#view_key ⇒ Object
35 36 37 38 39 40 |
# File 'lib/activerecord/materialized/view_configuration_class_methods.rb', line 35 def view_key return view_class.name.underscore if view_class.name.present? table = view_class.instance_variable_get(:@table_name) table.presence || "anonymous_view_#{view_class.object_id}" end |