Module: Roda::RodaPlugins::DebugBar::InstanceMethods

Defined in:
lib/roda/plugins/debug_bar.rb

Instance Method Summary collapse

Instance Method Details

#format_time(time) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/roda/plugins/debug_bar.rb', line 271

def format_time time

  # case time
  # in 1e-6...1e-3
  #   "#{time*1e6}μs"
  # in 1e-3...
  # end

  if time < 1e-3
    "#{(time*1e6).round}μs"
  elsif time < 1
    "#{(time*1e3).round(3)}ms"
  else
    "#{time}s"
  end

end

#highlight_ruby_hash(query) ⇒ Object



265
266
267
268
269
# File 'lib/roda/plugins/debug_bar.rb', line 265

def highlight_ruby_hash query
  formatter = Rouge::Formatters::HTML.new
  lexer = Rouge::Lexers::Ruby.new
  formatter.format(lexer.lex(query))
end

#log_error(message) ⇒ Object



220
221
222
# File 'lib/roda/plugins/debug_bar.rb', line 220

def log_error message
  @_debug_bar_instance.add_message(:error, message)
end

#log_info(message) ⇒ Object

module DebugLog



214
215
216
# File 'lib/roda/plugins/debug_bar.rb', line 214

def log_info message
  @_debug_bar_instance.add_message(:info, message)
end

#log_warn(message) ⇒ Object



217
218
219
# File 'lib/roda/plugins/debug_bar.rb', line 217

def log_warn message
  @_debug_bar_instance.add_message(:warn, message)
end

#relative_render(view) ⇒ Object

def grid_component(opts) end



254
255
256
# File 'lib/roda/plugins/debug_bar.rb', line 254

def relative_render view
  render('', path: File.join(__dir__, "../debug_bar/views/#{view}.erb"), ignore: true)
end

#render(path, opts = {}) ⇒ Object

def add_data(data)

if @@data_store.size < 5
  @@data_store << data
else
  @@data_store.unshift
  @@data_store.push data
end

end



235
236
237
238
239
240
241
# File 'lib/roda/plugins/debug_bar.rb', line 235

def render(path, opts = {})
  unless opts[:ignore]
    # puts "rendering #{path}"
    Roda::DebugBar::Current.add_view(path)
  end
  super
end

#sql_highlight(query) ⇒ Object



258
259
260
261
262
263
# File 'lib/roda/plugins/debug_bar.rb', line 258

def sql_highlight query
  formatter = Rouge::Formatters::HTML.new
  lexer = Rouge::Lexers::SQL.new
  sql = formatter.format(lexer.lex(query))
  sql.gsub('`', '&#96;')
end

#view(path, opts = {}) ⇒ Object



243
244
245
246
247
248
249
# File 'lib/roda/plugins/debug_bar.rb', line 243

def view(path, opts = {})
  unless opts[:ignore]
    # puts "view #{path}"
    Roda::DebugBar::Current.add_view(path)
  end
  super
end