123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Testing::EventReporterAssertions::EventCollector::Event

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activesupport/lib/active_support/testing/event_reporter_assertions.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(event_data) ⇒ Event

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/event_reporter_assertions.rb', line 14

def initialize(event_data)
  @event_data = event_data
end

Instance Attribute Details

#event_data (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/event_reporter_assertions.rb', line 12

attr_reader :event_data

Instance Method Details

#inspect

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/event_reporter_assertions.rb', line 18

def inspect
  "#{event_data[:name]} (payload: #{event_data[:payload].inspect}, tags: #{event_data[:tags].inspect})"
end

#matches?(name, payload, tags) ⇒ Boolean

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/event_reporter_assertions.rb', line 22

def matches?(name, payload, tags)
  return false unless name.to_s == event_data[:name]

  if payload && payload.is_a?(Hash)
    return false unless matches_hash?(payload, :payload)
  end

  return false unless matches_hash?(tags, :tags)
  true
end

#matches_hash?(expected_hash, event_key) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/event_reporter_assertions.rb', line 34

def matches_hash?(expected_hash, event_key)
  expected_hash.all? do |k, v|
    if v.is_a?(Regexp)
      event_data.dig(event_key, k).to_s.match?(v)
    else
      event_data.dig(event_key, k) == v
    end
  end
end