Module: Polytrix::Spies

Defined in:
lib/polytrix/spies.rb,
lib/polytrix/spies/file_system_spy.rb

Defined Under Namespace

Classes: FileSystemSpy

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.spiesObject (readonly)

Returns the value of attribute spies.



26
27
28
# File 'lib/polytrix/spies.rb', line 26

def spies
  @spies
end

Class Method Details

.middlewareObject



28
29
30
# File 'lib/polytrix/spies.rb', line 28

def middleware
  @middleware ||= Middleware::Builder.new
end

.observe(challenge, &blk) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/polytrix/spies.rb', line 41

def observe(challenge, &blk)
  middleware = Middleware::Builder.new
  spies.each do |spy|
    middleware.use spy
  end
  middleware.use blk
  middleware.call(challenge)
end

.register_spy(spy) ⇒ Object



36
37
38
39
# File 'lib/polytrix/spies.rb', line 36

def register_spy(spy)
  spies.add(spy)
  middleware.insert 0, spy, {}
end

.reportsObject



50
51
52
53
54
55
56
57
58
# File 'lib/polytrix/spies.rb', line 50

def reports
  # Group by type
  all_reports = spies.flat_map do |spy|
    spy.reports.to_a if spy.respond_to? :reports
  end
  all_reports.each_with_object({}) do |(k, v), h|
    (h[k] ||= []) << v
  end
end