Class: Card::Log::Performance::Entry
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#children_cnt ⇒ Object
Returns the value of attribute children_cnt.
-
#context ⇒ Object
Returns the value of attribute context.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#level ⇒ Object
Returns the value of attribute level.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
- #add_children(child = false) ⇒ Object
- #delete ⇒ Object
- #delete_children(child = false) ⇒ Object
- #has_younger_siblings? ⇒ Boolean
-
#initialize(parent, level, args) ⇒ Entry
constructor
A new instance of Entry.
- #save_duration ⇒ Object
- #to_html ⇒ Object
-
#to_s! ⇒ Object
deletes the children counts in order to print the tree; must be called in the right order.
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 = "#{ args[:title] || args[:method] || '' }" += ": #{ 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
#children ⇒ Object
Returns the value of attribute children.
336 337 338 |
# File 'lib/card/log.rb', line 336 def children @children end |
#children_cnt ⇒ Object
Returns the value of attribute children_cnt.
336 337 338 |
# File 'lib/card/log.rb', line 336 def children_cnt @children_cnt end |
#context ⇒ Object
Returns the value of attribute context.
336 337 338 |
# File 'lib/card/log.rb', line 336 def context @context end |
#duration ⇒ Object
Returns the value of attribute duration.
336 337 338 |
# File 'lib/card/log.rb', line 336 def duration @duration end |
#level ⇒ Object
Returns the value of attribute level.
336 337 338 |
# File 'lib/card/log.rb', line 336 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
337 338 339 |
# File 'lib/card/log.rb', line 337 def end |
#parent ⇒ Object
Returns the value of attribute parent.
336 337 338 |
# File 'lib/card/log.rb', line 336 def parent @parent end |
#valid ⇒ Object
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 |
#delete ⇒ Object
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
368 369 370 |
# File 'lib/card/log.rb', line 368 def has_younger_siblings? @parent && @parent.children_cnt > 0 #@sibling_nr end |
#save_duration ⇒ Object
372 373 374 |
# File 'lib/card/log.rb', line 372 def save_duration @duration = (Time.now - @start) * 1000 end |
#to_html ⇒ Object
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 += if 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 += if if @details msg += ", " + @details.to_s.gsub( "\n", "\n#{ indent(false) }#{' '* TAB_SIZE}" ) end @parent.delete_children if @parent msg end end |