Class: Graphiti::Debugger

Inherits:
Object show all
Defined in:
lib/graphiti/debugger.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.chunksObject

Returns the value of attribute chunks.



7
8
9
# File 'lib/graphiti/debugger.rb', line 7

def chunks
  @chunks
end

.debug_modelsObject

Returns the value of attribute debug_models.



7
8
9
# File 'lib/graphiti/debugger.rb', line 7

def debug_models
  @debug_models
end

.enabledObject

Returns the value of attribute enabled.



7
8
9
# File 'lib/graphiti/debugger.rb', line 7

def enabled
  @enabled
end

.preserveObject

Returns the value of attribute preserve.



7
8
9
# File 'lib/graphiti/debugger.rb', line 7

def preserve
  @preserve
end

.pryObject

Returns the value of attribute pry.



7
8
9
# File 'lib/graphiti/debugger.rb', line 7

def pry
  @pry
end

Class Method Details

.debugObject



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/graphiti/debugger.rb', line 106

def debug
  if enabled
    begin
      self.chunks = []
      yield
    ensure
      flush
      self.chunks = [] unless preserve
    end
  else
    yield
  end
end

.flushObject



128
129
130
131
132
133
134
135
# File 'lib/graphiti/debugger.rb', line 128

def flush
  Graphiti.broadcast(:flush_debug, {}) do |payload|
    payload[:chunks] = chunks
    graph_statements.each do |chunk|
      flush_chunk(chunk)
    end
  end
end

.on_data(name, start, stop, id, payload) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/graphiti/debugger.rb', line 12

def on_data(name, start, stop, id, payload)
  return [] unless enabled

  took = ((stop - start) * 1000.0).round(2)
  params = scrub_params(payload[:params])

  if payload[:exception]
    on_data_exception(payload, params)
  elsif payload[:sideload]
    if payload[:results]
      on_sideload_data(payload, params, took)
    end
  else
    on_primary_data(payload, params, took)
  end
end

.on_render(name, start, stop, id, payload) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/graphiti/debugger.rb', line 94

def on_render(name, start, stop, id, payload)
  return [] unless enabled

  add_chunk do |logs|
    took = ((stop - start) * 1000.0).round(2)
    logs << [""]
    logs << ["=== Graphiti Debug", :green, true]
    logs << ["Rendering:", :green, true]
    logs << ["Took: #{took}ms", :magenta, true]
  end
end

.to_aObject



120
121
122
123
124
125
126
# File 'lib/graphiti/debugger.rb', line 120

def to_a
  debugs = []
  graph_statements.each do |chunk|
    debugs << chunk_to_hash(chunk)
  end
  debugs
end