class TurboTest::StaticAnalysis::ActiveRecord::DiffCompute
Public Class Methods
new(new_snapshot, old_snapshot)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/diff_compute.rb, line 7 def initialize(new_snapshot, old_snapshot) @data = { new: new_snapshot, old: old_snapshot } end
Public Instance Methods
calc()
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/diff_compute.rb, line 11 def calc empty_diff.tap do |diff| compute(:extensions, diff[:extensions]) compute(:tables, diff[:tables]) end end
Private Instance Methods
compute(type, diff)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/diff_compute.rb, line 27 def compute(type, diff) compute_added_changed type, diff compute_deleted type, diff end
compute_added_changed(type, diff)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/diff_compute.rb, line 32 def compute_added_changed(type, diff) iterator = @data.dig(:new, type).each_pair iterator.each_with_object(diff) do |(name, fgpt), memo| old_data = @data.dig(:old, type) unless old_data[name] memo.added << name next memo end memo.changed << name if fgpt != old_data[name] end end
compute_deleted(type, diff)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/diff_compute.rb, line 44 def compute_deleted(type, diff) @data.dig(:old, type).each_key.each_with_object(diff) do |name, memo| memo.deleted << name unless @data.dig(:new, type)[name] end end
empty_diff()
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/diff_compute.rb, line 20 def empty_diff { extensions: Diff.new, tables: Diff.new } end