Class: Dommy::Internal::ObserverMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/internal/observer_matcher.rb

Overview

Matches a mutation target against an observed node based on observer options. Works exclusively with wrapped DOM nodes (not Nokogiri internals).

Instance Method Summary collapse

Constructor Details

#initializeObserverMatcher

Returns a new instance of ObserverMatcher.



8
9
# File 'lib/dommy/internal/observer_matcher.rb', line 8

def initialize
end

Instance Method Details

#matches?(observed_wrapped, target_wrapped, subtree:) ⇒ Boolean

Does this observer’s target scope match the mutation target? Returns true if:

- target == observed (exact match), OR
- subtree=true AND target is descendant of observed

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/dommy/internal/observer_matcher.rb', line 15

def matches?(observed_wrapped, target_wrapped, subtree:)
  return true if target_wrapped.equal?(observed_wrapped)
  return false unless subtree
  return false unless observed_wrapped.respond_to?(:contains?)

  observed_wrapped.contains?(target_wrapped)
end

#matches_document?(target_wrapped, subtree:) ⇒ Boolean

Special case: Document observation Matches if subtree=false (never) or target is in document (always)

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/dommy/internal/observer_matcher.rb', line 25

def matches_document?(target_wrapped, subtree:)
  return true if subtree
  false
end