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.
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/card/log.rb', line 341 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
#children ⇒ Object
Returns the value of attribute children.
338 339 340 |
# File 'lib/card/log.rb', line 338 def children @children end |
#children_cnt ⇒ Object
Returns the value of attribute children_cnt.
338 339 340 |
# File 'lib/card/log.rb', line 338 def children_cnt @children_cnt end |
#context ⇒ Object
Returns the value of attribute context.
338 339 340 |
# File 'lib/card/log.rb', line 338 def context @context end |
#duration ⇒ Object
Returns the value of attribute duration.
338 339 340 |
# File 'lib/card/log.rb', line 338 def duration @duration end |
#level ⇒ Object
Returns the value of attribute level.
338 339 340 |
# File 'lib/card/log.rb', line 338 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
339 340 341 |
# File 'lib/card/log.rb', line 339 def @message end |
#parent ⇒ Object
Returns the value of attribute parent.
338 339 340 |
# File 'lib/card/log.rb', line 338 def parent @parent end |
#valid ⇒ Object
Returns the value of attribute valid.
338 339 340 |
# File 'lib/card/log.rb', line 338 def valid @valid end |
Instance Method Details
#add_children(child = false) ⇒ Object
359 360 361 362 |
# File 'lib/card/log.rb', line 359 def add_children child=false @children_cnt += 1 @children << child if child end |
#delete ⇒ Object
378 379 380 381 |
# File 'lib/card/log.rb', line 378 def delete @valid = false @parent.delete_children(self) if @parent end |
#delete_children(child = false) ⇒ Object
364 365 366 367 368 |
# File 'lib/card/log.rb', line 364 def delete_children child=false @children_cnt -= 1 @children.delete child if child end |
#has_younger_siblings? ⇒ Boolean
370 371 372 |
# File 'lib/card/log.rb', line 370 def has_younger_siblings? @parent && @parent.children_cnt > 0 #@sibling_nr end |
#save_duration ⇒ Object
374 375 376 |
# File 'lib/card/log.rb', line 374 def save_duration @duration = (Time.now - @start) * 1000 end |
#to_html ⇒ Object
403 404 405 406 407 408 409 410 |
# File 'lib/card/log.rb', line 403 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
390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/card/log.rb', line 390 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 |