Class: VcrStripeWebhook::EventCassette

Inherits:
Object
  • Object
show all
Defined in:
lib/vcr_stripe_webhook/event_cassette.rb

Defined Under Namespace

Classes: Data, Wait

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, vcr_cassette, recording) ⇒ EventCassette

Returns a new instance of EventCassette.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 12

def initialize(name, vcr_cassette, recording)
  @mutex = Mutex.new
  @name = name
  @vcr_cassette = vcr_cassette
  @recording = recording
  if recording
    @data = Data.new
  else
    @data = Data.deserialize(path)
    @wait_counter = 0
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 10

def name
  @name
end

#vcr_cassetteObject (readonly)

Returns the value of attribute vcr_cassette.



10
11
12
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 10

def vcr_cassette
  @vcr_cassette
end

Instance Method Details

#pathObject



25
26
27
28
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 25

def path
  dir = VcrStripeWebhook.configuration.cassette_library_dir
  File.join(dir, "#{name}.stripe_webhooks.yml")
end

#receive_event_payload(event) ⇒ Object



42
43
44
45
46
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 42

def receive_event_payload(event)
  @mutex.synchronize do
    @data.events.push(event)
  end
end

#recording?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 30

def recording?
  @recording
end

#serializeObject



48
49
50
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 48

def serialize
  @data.serialize(path)
end

#wait_for_events(waiter, timeout:, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 34

def wait_for_events(waiter, timeout:, &block)
  if recording?
    record_and_wait_for_events(waiter, timeout: timeout, &block)
  else
    replay_and_wait_for_events(waiter, &block)
  end
end