Module: ActiveDelivery::TestDelivery

Included in:
Base
Defined in:
lib/active_delivery/testing.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clearObject



37
38
39
40
# File 'lib/active_delivery/testing.rb', line 37

def clear
  store.clear
  lines.clear
end

.enableObject

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
# File 'lib/active_delivery/testing.rb', line 6

def enable
  raise ArgumentError, "block is required" unless block_given?
  begin
    clear
    Thread.current.thread_variable_set(:active_delivery_testing, true)
    yield
  ensure
    Thread.current.thread_variable_set(:active_delivery_testing, false)
  end
end

.enabled?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/active_delivery/testing.rb', line 17

def enabled?
  Thread.current.thread_variable_get(:active_delivery_testing) == true
end

.linesObject



33
34
35
# File 'lib/active_delivery/testing.rb', line 33

def lines
  Thread.current.thread_variable_get(:active_delivery_testing_lines) || Thread.current.thread_variable_set(:active_delivery_testing_lines, [])
end

.storeObject



29
30
31
# File 'lib/active_delivery/testing.rb', line 29

def store
  Thread.current.thread_variable_get(:active_delivery_testing_store) || Thread.current.thread_variable_set(:active_delivery_testing_store, [])
end

.track(delivery, options) ⇒ Object



21
22
23
# File 'lib/active_delivery/testing.rb', line 21

def track(delivery, options)
  store << [delivery, options]
end

.track_line(line) ⇒ Object



25
26
27
# File 'lib/active_delivery/testing.rb', line 25

def track_line(line)
  lines << line
end

Instance Method Details

#notify_line(line) ⇒ Object



49
50
51
52
# File 'lib/active_delivery/testing.rb', line 49

def notify_line(line, ...)
  res = super
  TestDelivery.track_line(line) if res
end

#perform_notify(delivery, **options) ⇒ Object



43
44
45
46
47
# File 'lib/active_delivery/testing.rb', line 43

def perform_notify(delivery, **options)
  return super unless test?
  TestDelivery.track(delivery, options)
  nil
end

#test?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/active_delivery/testing.rb', line 54

def test?
  TestDelivery.enabled?
end