Class: Byebug::RegularState
- Extended by:
- Forwardable
- Includes:
- Helpers::FileHelper
- Defined in:
- lib/byebug/states/regular_state.rb
Overview
Controls state of Byebug’s REPL when in normal mode
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#display ⇒ Object
Returns the value of attribute display.
-
#file ⇒ Object
Returns the value of attribute file.
-
#frame ⇒ Object
Returns the value of attribute frame.
-
#interface ⇒ Object
writeonly
Sets the attribute interface.
-
#line ⇒ Object
Returns the value of attribute line.
-
#prev_line ⇒ Object
Returns the value of attribute prev_line.
Attributes inherited from State
Instance Method Summary collapse
-
#c_frame?(pos) ⇒ Boolean
Checks whether the frame in position
pos
is a c-frame or not. -
#frame_args(pos) ⇒ Object
Builds a string containing all available args in frame number
pos
, in a verbose or non verbose way according to the value of thecallstyle
setting. -
#frame_block_and_method(pos) ⇒ Object
Builds a formatted string containing information about block and method of the frame in position
pos
. -
#frame_call(pos) ⇒ Object
Builds a formatted string containing information about current method call in frame number
pos
. -
#frame_class(pos) ⇒ Object
Builds a string containing the class associated to frame number
pos
or an empty string if the currentcallstyle
setting is ‘short’. -
#frame_file(pos) ⇒ Object
Formatted filename in frame number
pos
. -
#frame_line(pos) ⇒ Object
Line number in frame number
pos
. -
#frame_mark(pos) ⇒ Object
Formatted mark for number of frame in position
pos
. -
#frame_pos(pos) ⇒ Object
Properly formatted frame number of frame in position
pos
. -
#initialize(context, display, file, interface, line) ⇒ RegularState
constructor
A new instance of RegularState.
-
#location ⇒ Object
Current (formatted) location.
-
#proceed ⇒ Object
Signals the REPL that the execution can proceed.
-
#proceed? ⇒ Boolean
Checks whether that execution can proceed.
Methods included from Helpers::FileHelper
#get_line, #get_lines, #n_lines, #normalize
Constructor Details
#initialize(context, display, file, interface, line) ⇒ RegularState
Returns a new instance of RegularState.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/byebug/states/regular_state.rb', line 14 def initialize(context, display, file, interface, line) super(interface) @context = context @display = display @file = file @frame = 0 @line = line @prev_line = nil @proceed = false end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
11 12 13 |
# File 'lib/byebug/states/regular_state.rb', line 11 def context @context end |
#display ⇒ Object
Returns the value of attribute display.
11 12 13 |
# File 'lib/byebug/states/regular_state.rb', line 11 def display @display end |
#file ⇒ Object
Returns the value of attribute file.
11 12 13 |
# File 'lib/byebug/states/regular_state.rb', line 11 def file @file end |
#frame ⇒ Object
Returns the value of attribute frame.
11 12 13 |
# File 'lib/byebug/states/regular_state.rb', line 11 def frame @frame end |
#interface=(value) ⇒ Object (writeonly)
Sets the attribute interface
12 13 14 |
# File 'lib/byebug/states/regular_state.rb', line 12 def interface=(value) @interface = value end |
#line ⇒ Object
Returns the value of attribute line.
11 12 13 |
# File 'lib/byebug/states/regular_state.rb', line 11 def line @line end |
#prev_line ⇒ Object
Returns the value of attribute prev_line.
11 12 13 |
# File 'lib/byebug/states/regular_state.rb', line 11 def prev_line @prev_line end |
Instance Method Details
#c_frame?(pos) ⇒ Boolean
Checks whether the frame in position pos
is a c-frame or not
163 164 165 |
# File 'lib/byebug/states/regular_state.rb', line 163 def c_frame?(pos) context.frame_binding(pos).nil? end |
#frame_args(pos) ⇒ Object
Builds a string containing all available args in frame number pos
, in a verbose or non verbose way according to the value of the callstyle
setting
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/byebug/states/regular_state.rb', line 86 def frame_args(pos) args = context.frame_args(pos) return '' if args.empty? locals = context.frame_locals(pos) unless Setting[:callstyle] == 'short' my_args = args.map do |arg| prefix, default = prefix_and_default_from(arg[0]) kls = if Setting[:callstyle] == 'short' || arg[1].nil? || locals.empty? '' else "##{locals[arg[1]].class}" end "#{prefix}#{arg[1] || default}#{kls}" end "(#{my_args.join(', ')})" end |
#frame_block_and_method(pos) ⇒ Object
Builds a formatted string containing information about block and method of the frame in position pos
72 73 74 75 76 77 |
# File 'lib/byebug/states/regular_state.rb', line 72 def frame_block_and_method(pos) deco_regexp = /((?:block(?: \(\d+ levels\))?|rescue) in )?(.+)/ deco_method = "#{context.frame_method(pos)}" block_and_method = deco_regexp.match(deco_method)[1..2] block_and_method.map { |x| x.nil? ? '' : x } end |
#frame_call(pos) ⇒ Object
Builds a formatted string containing information about current method call in frame number pos
.
112 113 114 115 116 |
# File 'lib/byebug/states/regular_state.rb', line 112 def frame_call(pos) block, method = frame_block_and_method(pos) block + frame_class(pos) + method + frame_args(pos) end |
#frame_class(pos) ⇒ Object
Builds a string containing the class associated to frame number pos
or an empty string if the current callstyle
setting is ‘short’
57 58 59 60 61 62 63 64 |
# File 'lib/byebug/states/regular_state.rb', line 57 def frame_class(pos) return '' if Setting[:callstyle] == 'short' klass = context.frame_class(pos) return '' if klass.to_s.empty? "#{klass}." end |
#frame_file(pos) ⇒ Object
Formatted filename in frame number pos
123 124 125 126 |
# File 'lib/byebug/states/regular_state.rb', line 123 def frame_file(pos) fullpath = context.frame_file(pos) Setting[:fullpath] ? fullpath : shortpath(fullpath) end |
#frame_line(pos) ⇒ Object
Line number in frame number pos
133 134 135 |
# File 'lib/byebug/states/regular_state.rb', line 133 def frame_line(pos) context.frame_line(pos) end |
#frame_mark(pos) ⇒ Object
Formatted mark for number of frame in position pos
. The mark can contain the current frame symbo (–>), the c_frame symbol (ͱ–) or both
152 153 154 155 156 |
# File 'lib/byebug/states/regular_state.rb', line 152 def frame_mark(pos) mark = frame == pos ? '-->' : ' ' c_frame?(pos) ? mark + ' ͱ--' : mark end |
#frame_pos(pos) ⇒ Object
Properly formatted frame number of frame in position pos
142 143 144 |
# File 'lib/byebug/states/regular_state.rb', line 142 def frame_pos(pos) format('%-2d', pos) end |
#location ⇒ Object
Current (formatted) location
45 46 47 48 49 |
# File 'lib/byebug/states/regular_state.rb', line 45 def location l = "#{normalize(file)} @ #{line}\n" l += "#{get_line(file, line)}\n" unless %w((irb) -e').include?(file) l end |
#proceed ⇒ Object
Signals the REPL that the execution can proceed
38 39 40 |
# File 'lib/byebug/states/regular_state.rb', line 38 def proceed @proceed = true end |
#proceed? ⇒ Boolean
Checks whether that execution can proceed
31 32 33 |
# File 'lib/byebug/states/regular_state.rb', line 31 def proceed? @proceed end |