Module: ActiveDelivery::TestDelivery
- Included in:
- Base
- Defined in:
- lib/active_delivery/testing.rb
Class Method Summary collapse
- .clear ⇒ Object
- .enable ⇒ Object
- .enabled? ⇒ Boolean
- .lines ⇒ Object
- .store ⇒ Object
- .track(delivery, options) ⇒ Object
- .track_line(line) ⇒ Object
Instance Method Summary collapse
Class Method Details
.clear ⇒ Object
37 38 39 40 |
# File 'lib/active_delivery/testing.rb', line 37 def clear store.clear lines.clear end |
.enable ⇒ Object
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
17 18 19 |
# File 'lib/active_delivery/testing.rb', line 17 def enabled? Thread.current.thread_variable_get(:active_delivery_testing) == true end |
.lines ⇒ Object
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 |
.store ⇒ Object
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, ) store << [delivery, ] 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, **) return super unless test? TestDelivery.track(delivery, ) nil end |
#test? ⇒ Boolean
54 55 56 |
# File 'lib/active_delivery/testing.rb', line 54 def test? TestDelivery.enabled? end |