Skip to content

Commit

Permalink
Add prepend and append to ChangeObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
psparrow committed May 5, 2021
1 parent 22b81ae commit f509421
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/bootsnap/load_path_cache/change_observer.rb
Expand Up @@ -15,11 +15,13 @@ def push(*entries)
@lpc_observer.push_paths(self, *entries.map(&:to_s))
super
end
alias_method :append, :push

def unshift(*entries)
@lpc_observer.unshift_paths(self, *entries.map(&:to_s))
super
end
alias_method :prepend, :unshift

def concat(entries)
@lpc_observer.push_paths(self, *entries.map(&:to_s))
Expand Down
23 changes: 17 additions & 6 deletions test/load_path_cache/change_observer_test.rb
Expand Up @@ -17,18 +17,29 @@ def test_observes_changes
@observer.expects(:push_paths).with(@arr, 'b', 'c')
@arr.push('b', 'c')

@observer.expects(:unshift_paths).with(@arr, 'd', 'e')
@arr.unshift('d', 'e')
@observer.expects(:push_paths).with(@arr, 'd', 'e')
@arr.append('d', 'e')

@observer.expects(:push_paths).with(@arr, 'f', 'g')
@arr.concat(%w(f g))
@observer.expects(:unshift_paths).with(@arr, 'f', 'g')
@arr.unshift('f', 'g')

@observer.expects(:push_paths).with(@arr, 'h', 'i')
@arr.concat(%w(h i))

@observer.expects(:unshift_paths).with(@arr, 'j', 'k')
@arr.prepend('j', 'k')
end

def test_reinitializes_on_aggressive_modifications
@observer.expects(:push_paths).with(@arr, 'a', 'b', 'c')
@arr.push('a', 'b', 'c')

@observer.expects(:reinitialize).times(4)
@arr.delete(3)
@arr.compact!
@arr.map!(&:upcase)
assert_equal('G', @arr.pop)
assert_equal(%w(D E A B C F), @arr)
assert_equal('C', @arr.pop)
assert_equal(%w(A B), @arr)
end

def test_register_frozen
Expand Down

0 comments on commit f509421

Please sign in to comment.