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 000c1ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 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
14 changes: 10 additions & 4 deletions test/load_path_cache/change_observer_test.rb
Expand Up @@ -17,11 +17,17 @@ 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')

@observer.expects(:reinitialize).times(4)
@arr.delete(3)
Expand Down

0 comments on commit 000c1ba

Please sign in to comment.