Class: Upkeep::Dependencies::ActiveRecordCollection
- Defined in:
- lib/upkeep/dependencies.rb
Direct Known Subclasses
Constant Summary collapse
- UNKNOWN =
Object.new
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #collection_lookup_columns ⇒ Object
- #collection_lookup_tables ⇒ Object
-
#initialize(primary_table:, table_columns:, coverage:, sql:, predicates: [], source: :active_record_collection, precision: :collection_predicate) ⇒ ActiveRecordCollection
constructor
A new instance of ActiveRecordCollection.
- #matches_change?(change) ⇒ Boolean
- #precision ⇒ Object
Methods inherited from Base
#cache_key, #identity?, #identity_key, #narrow_frame_safe?, #to_h, #visibility
Constructor Details
#initialize(primary_table:, table_columns:, coverage:, sql:, predicates: [], source: :active_record_collection, precision: :collection_predicate) ⇒ ActiveRecordCollection
Returns a new instance of ActiveRecordCollection.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/upkeep/dependencies.rb', line 118 def initialize( primary_table:, table_columns:, coverage:, sql:, predicates: [], source: :active_record_collection, precision: :collection_predicate ) table_columns = normalize_table_columns(table_columns) coverage = coverage.to_sym unless coverage == :columns raise ArgumentError, "unsupported Active Record predicate coverage: #{coverage}; collection dependencies require proven column coverage" end @precision = precision.to_sym super( source: source.to_sym, key: { table: primary_table, predicate_digest: Digest::SHA256.hexdigest(sql)[0, 16] }, metadata: { primary_table: primary_table, table_columns: table_columns, coverage: coverage.to_s, sql: sql, predicates: normalize_predicates(predicates) } ) end |
Instance Method Details
#collection_lookup_columns ⇒ Object
171 172 173 174 175 |
# File 'lib/upkeep/dependencies.rb', line 171 def collection_lookup_columns table_columns.flat_map do |table, columns| columns.map { |column| [table, column] } end.sort end |
#collection_lookup_tables ⇒ Object
167 168 169 |
# File 'lib/upkeep/dependencies.rb', line 167 def collection_lookup_tables table_columns.keys.sort end |
#matches_change?(change) ⇒ Boolean
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/upkeep/dependencies.rb', line 151 def matches_change?(change) return false unless table_columns.key?(change.fetch(:table)) predicate_match = predicate_match(change) return predicate_match unless predicate_match == UNKNOWN return true if create_change?(change) return true if delete_change?(change) table_columns.fetch(change.fetch(:table)).intersect?(change.fetch(:changed_attributes, [])) end |
#precision ⇒ Object
163 164 165 |
# File 'lib/upkeep/dependencies.rb', line 163 def precision @precision end |