Class: IRT::Log
Defined Under Namespace
Classes: BindingHunk, FileHunk, Hunk, InspectHunk, InteractiveHunk
Instance Attribute Summary collapse
-
#ignored_commands ⇒ Object
Returns the value of attribute ignored_commands.
-
#ignored_echo_commands ⇒ Object
Returns the value of attribute ignored_echo_commands.
-
#non_setting_commands ⇒ Object
Returns the value of attribute non_setting_commands.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#tail_size ⇒ Object
Returns the value of attribute tail_size.
Class Method Summary collapse
Instance Method Summary collapse
- #add_hunk ⇒ Object
- #add_line(content, line_no) ⇒ Object
-
#initialize ⇒ Log
constructor
A new instance of Log.
- #pop_status ⇒ Object
-
#print(limit = nil) ⇒ Object
nil prints all.
- #print_running_file ⇒ Object
- #print_status ⇒ Object
Constructor Details
#initialize ⇒ Log
Returns a new instance of Log.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/irt/log.rb', line 7 def initialize @ignored_echo_commands = FileUtils.own_methods + [:_] @ignored_echo_commands = @ignored_echo_commands.map(&:to_sym) @ignored_commands = @ignored_echo_commands + IRB::ExtendCommandBundle.instance_methods + [ :p, :pp, :ap, :y, :puts, :print, :irt, :irb ] @ignored_commands += IRT::Commands::Rails.own_methods if defined?(IRT::Commands::Rails) @ignored_commands = @ignored_commands.map(&:to_sym) @non_setting_commands = @ignored_commands + IRT::Directives.own_methods @non_setting_commands = @non_setting_commands.map(&:to_sym) @tail_size = tail_size || 10 self << FileHunk.new(IRT.irt_file) @status = [[IRT.irt_file.basename, :file]] end |
Instance Attribute Details
#ignored_commands ⇒ Object
Returns the value of attribute ignored_commands.
4 5 6 |
# File 'lib/irt/log.rb', line 4 def ignored_commands @ignored_commands end |
#ignored_echo_commands ⇒ Object
Returns the value of attribute ignored_echo_commands.
4 5 6 |
# File 'lib/irt/log.rb', line 4 def ignored_echo_commands @ignored_echo_commands end |
#non_setting_commands ⇒ Object
Returns the value of attribute non_setting_commands.
4 5 6 |
# File 'lib/irt/log.rb', line 4 def non_setting_commands @non_setting_commands end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/irt/log.rb', line 5 def status @status end |
#tail_size ⇒ Object
Returns the value of attribute tail_size.
4 5 6 |
# File 'lib/irt/log.rb', line 4 def tail_size @tail_size end |
Class Method Details
Instance Method Details
#add_hunk ⇒ Object
22 23 24 25 |
# File 'lib/irt/log.rb', line 22 def add_hunk mode = IRB.CurrentContext.irt_mode push eval("#{mode.to_s.capitalize + 'Hunk'}.new") end |
#add_line(content, line_no) ⇒ Object
27 28 29 |
# File 'lib/irt/log.rb', line 27 def add_line(content, line_no) last.add_line(content, line_no) end |
#pop_status ⇒ Object
77 78 79 80 81 82 |
# File 'lib/irt/log.rb', line 77 def pop_status name, mode = status.pop return if mode == :file puts IRT.dye(" <<", :log_color, :bold) + status_segment(name, mode) puts end |
#print(limit = nil) ⇒ Object
nil prints all
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/irt/log.rb', line 35 def print(limit=nil) # nil prints all hist = dup hist.delete_if{|h| h.empty? } to_render = hist.reduce([]) do |his, hunk| hu = hunk.dup (his.empty? || his.last.header != hu.header) ? (his << hu) : his.last.concat(hu) his end if to_render.empty? print_header '(empty)' else to_print = 0 if limit.nil? || to_render.map(&:size).inject(:+) <= limit to_print = to_render.map(&:size).inject(:+) latest_lines = nil print_header else rest = limit to_render.reverse.each do |h| to_print += 1 if rest > h.size rest = rest - h.size next else latest_lines = rest break end end print_header '(tail)' end to_render = to_render.last(to_print) to_render.shift.render(latest_lines) to_render.each{|h| h.render } end puts end |