Class: Card::Log::Performance::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/card/log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, level, args) ⇒ Entry

Returns a new instance of Entry.



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/card/log.rb', line 339

def initialize( parent, level, args )
  @start = Time.new
  @message = "#{ args[:title] ||  args[:method] || '' }"
  @message += ": #{ args[:message] }" if args[:message]
  @details = args[:details]
  @context = args[:context]
  @level = level
  @duration = nil
  @valid = true
  @parent = parent
  @children_cnt = 0
  @children = []
  if @parent
    @parent.add_children self
    #@sibling_nr = @parent.children_cnt
  end
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



336
337
338
# File 'lib/card/log.rb', line 336

def children
  @children
end

#children_cntObject

Returns the value of attribute children_cnt.



336
337
338
# File 'lib/card/log.rb', line 336

def children_cnt
  @children_cnt
end

#contextObject

Returns the value of attribute context.



336
337
338
# File 'lib/card/log.rb', line 336

def context
  @context
end

#durationObject

Returns the value of attribute duration.



336
337
338
# File 'lib/card/log.rb', line 336

def duration
  @duration
end

#levelObject

Returns the value of attribute level.



336
337
338
# File 'lib/card/log.rb', line 336

def level
  @level
end

#messageObject (readonly)

Returns the value of attribute message.



337
338
339
# File 'lib/card/log.rb', line 337

def message
  @message
end

#parentObject

Returns the value of attribute parent.



336
337
338
# File 'lib/card/log.rb', line 336

def parent
  @parent
end

#validObject

Returns the value of attribute valid.



336
337
338
# File 'lib/card/log.rb', line 336

def valid
  @valid
end

Instance Method Details

#add_children(child = false) ⇒ Object



357
358
359
360
# File 'lib/card/log.rb', line 357

def add_children child=false
  @children_cnt += 1
  @children << child if child
end

#deleteObject



376
377
378
379
# File 'lib/card/log.rb', line 376

def delete
  @valid = false
  @parent.delete_children(self) if @parent
end

#delete_children(child = false) ⇒ Object



362
363
364
365
366
# File 'lib/card/log.rb', line 362

def delete_children child=false
  @children_cnt -= 1
  @children.delete child if child

end

#has_younger_siblings?Boolean

Returns:

  • (Boolean)


368
369
370
# File 'lib/card/log.rb', line 368

def has_younger_siblings?
  @parent && @parent.children_cnt > 0 #@sibling_nr
end

#save_durationObject



372
373
374
# File 'lib/card/log.rb', line 372

def save_duration
  @duration = (Time.now - @start) * 1000
end

#to_htmlObject



401
402
403
404
405
406
407
408
# File 'lib/card/log.rb', line 401

def to_html
  @to_html ||= begin
    msg = "<span title='#{@details}'>"
    msg += @message if @message
    msg += "<span class='badge #{"badge-danger" if @duration > 100}'> %d.2ms </span>" % @duration if @duration
    msg += '</span>'
  end
end

#to_s!Object

deletes the children counts in order to print the tree; must be called in the right order

More robuts but more expensive approach: use @sibling_nr instead of counting @children_cnt down, but @sibling_nr has to be updated for all siblings of an entry if the entry gets deleted due to min_time or max_depth restrictions in the config, so we have to save all children relations for that



388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/card/log.rb', line 388

def to_s!
  @to_s ||= begin
    msg = indent
    msg += "(%d.2ms) " % @duration if @duration
    msg += @message if @message

    if @details
      msg +=  ", " + @details.to_s.gsub( "\n", "\n#{ indent(false) }#{' '* TAB_SIZE}" )
    end
    @parent.delete_children if @parent
    msg
  end
end