Class: IRT::Log

Inherits:
Array show all
Defined in:
lib/irt/log.rb,
lib/irt/hunks.rb

Defined Under Namespace

Classes: BindingHunk, FileHunk, Hunk, InspectHunk, InteractiveHunk

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLog

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_commandsObject

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_commandsObject

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_commandsObject

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

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/irt/log.rb', line 5

def status
  @status
end

#tail_sizeObject

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



31
32
33
# File 'lib/irt/log.rb', line 31

def self.print_border
  print IRT.dye(' ','', :log_color, :reversed)
end

Instance Method Details

#add_hunkObject



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_statusObject



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

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


84
85
86
87
# File 'lib/irt/log.rb', line 84

def print_running_file
  run_str = "Running: #{IRT.irt_file}"
  puts IRT.dye(" #{run_str} ", "*** #{run_str} ***", :file_color, :bold, :reversed)
end


72
73
74
75
# File 'lib/irt/log.rb', line 72

def print_status
  segments = status.map {|name,mode| status_segment(name,mode)}
  puts segments.join(IRT.dye(">>", :log_color, :bold))
end