class PropCheck::Hooks::Enumerable
@api private Wraps enumerable `inner` with a `PropCheck::Hooks` object such that the before/after/around hooks are called before/after/around each element that is fetched from `inner`.
This is very helpful if you need to perform cleanup logic before/after/around e.g. data is generated or fetched.
Note that whatever is after a `yield` in an `around` hook is not guaranteed to be called (for instance when a StopIteration is raised). Thus: make sure you use `ensure` to clean up resources.
Public Class Methods
new(inner, hooks)
click to toggle source
# File lib/prop_check/hooks.rb, line 114 def initialize(inner, hooks) @inner = inner @hooks = hooks end
Public Instance Methods
each() { |next(&task)| ... }
click to toggle source
# File lib/prop_check/hooks.rb, line 119 def each(&task) return to_enum(:each) unless block_given? enum = @inner.to_enum wrapped_yielder = @hooks.wrap_block do yield enum.next(&task) end loop(&wrapped_yielder) end