Class: Card::Log::Performance::Entry
Instance Attribute Summary collapse
-
#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.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
- #add_children ⇒ Object
- #delete ⇒ Object
- #delete_children ⇒ Object
- #has_younger_siblings? ⇒ Boolean
-
#initialize(parent, level, args) ⇒ Entry
constructor
A new instance of Entry.
- #save_duration ⇒ 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
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/card/log.rb', line 258 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 if @parent @parent.add_children #@sibling_nr = @parent.children_cnt end end |
Instance Attribute Details
#children_cnt ⇒ Object
Returns the value of attribute children_cnt.
256 257 258 |
# File 'lib/card/log.rb', line 256 def children_cnt @children_cnt end |
#context ⇒ Object
Returns the value of attribute context.
256 257 258 |
# File 'lib/card/log.rb', line 256 def context @context end |
#duration ⇒ Object
Returns the value of attribute duration.
256 257 258 |
# File 'lib/card/log.rb', line 256 def duration @duration end |
#level ⇒ Object
Returns the value of attribute level.
256 257 258 |
# File 'lib/card/log.rb', line 256 def level @level end |
#parent ⇒ Object
Returns the value of attribute parent.
256 257 258 |
# File 'lib/card/log.rb', line 256 def parent @parent end |
#valid ⇒ Object
Returns the value of attribute valid.
256 257 258 |
# File 'lib/card/log.rb', line 256 def valid @valid end |
Instance Method Details
#add_children ⇒ Object
275 276 277 |
# File 'lib/card/log.rb', line 275 def add_children @children_cnt += 1 end |
#delete ⇒ Object
291 292 293 294 |
# File 'lib/card/log.rb', line 291 def delete @valid = false @parent.delete_children if @parent end |
#delete_children ⇒ Object
279 280 281 |
# File 'lib/card/log.rb', line 279 def delete_children @children_cnt -= 1 end |
#has_younger_siblings? ⇒ Boolean
283 284 285 |
# File 'lib/card/log.rb', line 283 def has_younger_siblings? @parent && @parent.children_cnt > 0 #@sibling_nr end |
#save_duration ⇒ Object
287 288 289 |
# File 'lib/card/log.rb', line 287 def save_duration @duration = (Time.now - @start) * 1000 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
303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/card/log.rb', line 303 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 |