Class: PowerTrace::Stack

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/power_trace/stack.rb

Constant Summary collapse

OUTPUT_OPTIONS_DEFAULT =
{
  colorize: true,
  line_limit: 100,
  extra_info_indent: 4
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Stack

Returns a new instance of Stack.



16
17
18
19
20
# File 'lib/power_trace/stack.rb', line 16

def initialize(options = {})
  @options = options
  @exception = options.fetch(:exception, false)
  @entries = extract_entries.compact
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



8
9
10
# File 'lib/power_trace/stack.rb', line 8

def entries
  @entries
end

Instance Method Details

#each(&block) ⇒ Object



22
23
24
# File 'lib/power_trace/stack.rb', line 22

def each(&block)
  @entries.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/power_trace/stack.rb', line 36

def empty?
  @entries.empty?
end

#to_backtrace(output_options = {}) ⇒ Object



26
27
28
29
30
# File 'lib/power_trace/stack.rb', line 26

def to_backtrace(output_options = {})
  output_options[:colorize] = output_options.fetch(:colorize, PowerTrace.colorize_backtrace) if @exception
  output_options = extract_output_options(output_options)
  @entries.map { |e| e.to_s(output_options) }
end

#to_s(output_options = {}) ⇒ Object



32
33
34
# File 'lib/power_trace/stack.rb', line 32

def to_s(output_options = {})
  to_backtrace(output_options).join("\n")
end