irt 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/irt/init.rb ADDED
@@ -0,0 +1 @@
1
+ puts "WARNING: The use of 'irt/init' has no effects and is deprecated. You might want to remove it from your ~/.irtrc file".error_color
data/lib/irt/log.rb ADDED
@@ -0,0 +1,94 @@
1
+ module IRT
2
+ class Log < Array
3
+
4
+ attr_accessor :ignored_commands, :ignored_echo_commands, :non_setting_commands, :tail_size, :status
5
+
6
+ def initialize
7
+ @ignored_echo_commands = FileUtils.own_methods
8
+ @ignored_commands = @ignored_echo_commands +
9
+ IRB::ExtendCommandBundle.instance_methods +
10
+ %w[ p pp ap y puts print irt irb ]
11
+ @non_setting_commands = @ignored_commands + IRT::Directives.own_methods
12
+ @tail_size = tail_size || 10
13
+ self << FileHunk.new(IRT.irt_file)
14
+ @status = [[File.basename(IRT.irt_file), :file]]
15
+ end
16
+
17
+ def add_hunk
18
+ mode = IRB.CurrentContext.irt_mode
19
+ push eval("#{mode.to_s.capitalize + 'Hunk'}.new")
20
+ end
21
+
22
+ def add_line(content, line_no)
23
+ last.add_line(content, line_no)
24
+ end
25
+
26
+ def self.print_border
27
+ print ' '.log_color.reversed.or('')
28
+ end
29
+
30
+ def print(limit=nil) # nil prints all
31
+ hist = dup
32
+ hist.delete_if{|h| h.empty? }
33
+ to_render = hist.reduce([]) do |his, hunk|
34
+ hu = hunk.dup
35
+ (his.empty? || his.last.header != hu.header) ? (his << hu) : his.last.concat(hu)
36
+ his
37
+ end
38
+ if to_render.empty?
39
+ print_header '(empty)'
40
+ else
41
+ to_print = 0
42
+ if limit.nil? || to_render.map(&:size).inject(:+) <= limit
43
+ to_print = to_render.map(&:size).inject(:+)
44
+ latest_lines = nil
45
+ print_header
46
+ else
47
+ rest = limit
48
+ to_render.reverse.each do |h|
49
+ to_print += 1
50
+ if rest > h.size
51
+ rest = rest - h.size
52
+ next
53
+ else
54
+ latest_lines = rest
55
+ break
56
+ end
57
+ end
58
+ print_header '(tail)'
59
+ end
60
+ to_render = to_render.last(to_print)
61
+ to_render.shift.render(latest_lines)
62
+ to_render.each{|h| h.render }
63
+ end
64
+ puts
65
+ end
66
+
67
+ def print_status
68
+ segments = status.map {|name,mode| status_segment(name,mode)}
69
+ puts segments.join(">>".log_color.bold)
70
+ end
71
+
72
+ def pop_status
73
+ name, mode = status.pop
74
+ return if mode == :file
75
+ puts " <<".log_color.bold + status_segment(name, mode)
76
+ puts
77
+ end
78
+
79
+ def print_running_file
80
+ puts " Running: #{IRT.irt_file} ".file_color.reversed.bold.or("*** Runing: #{IRT.irt_file} ***")
81
+ end
82
+
83
+ private
84
+
85
+ def print_header(tail_str='')
86
+ puts
87
+ puts " Virtual Log#{' '+ tail_str unless tail_str.empty?} ".log_color.bold.reversed.or('***** IRT Log *****')
88
+ end
89
+
90
+ def status_segment(name, mode)
91
+ " #{name} ".send("#{mode}_color".to_sym).bold.reversed.or("[#{name}]")
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,59 @@
1
+ module IRT
2
+ module Session
3
+ extend self
4
+
5
+ def enter(mode, obj=nil)
6
+ IRT.log.print if IRT.tail_on_irt
7
+ ws = obj ? IRB::WorkSpace.new(obj) : IRB.CurrentContext.workspace
8
+ new_irb = IRB::Irb.new(ws)
9
+ IRT.session_no += 1
10
+ main_name = mode == :inspect ?
11
+ IRB.CurrentContext.current_line.match(/^\s*(?:irb|irt|irt_inspect)\s+(.*)$/).captures[0].strip :
12
+ new_irb.context.workspace.main.to_s
13
+ main_name = main_name[0..30] + '...' if main_name.size > 30
14
+ new_irb.context.irb_name = "irt##{IRT.session_no}(#{main_name})"
15
+ new_irb.context.irb_path = "(irt##{IRT.session_no})"
16
+ set_binding_file_pointers(new_irb.context) if mode == :binding
17
+ eval_input(new_irb.context, mode)
18
+ end
19
+
20
+ def eval_input(new_context, mode)
21
+ new_context.parent_context = IRB.CurrentContext
22
+ new_context.set_last_value( IRB.CurrentContext.last_value ) unless (mode == :inspect || mode == :binding)
23
+ new_context.irt_mode = mode
24
+ new_context.backtrace_map = IRB.CurrentContext.backtrace_map if mode == :interactive
25
+ IRB.conf[:MAIN_CONTEXT] = new_context
26
+ IRT.log.add_hunk
27
+ IRT.log.status << [new_context.irb_name, mode]
28
+ IRT.log.print_status unless mode == :file
29
+ catch(:IRB_EXIT) { new_context.irb.eval_input }
30
+ end
31
+
32
+ def exit
33
+ exiting_context = IRB.conf[:MAIN_CONTEXT]
34
+ resuming_context = exiting_context.parent_context
35
+ exiting_mode = exiting_context.irt_mode
36
+ resuming_context.set_last_value( exiting_context.last_value ) \
37
+ unless (exiting_mode == :inspect || exiting_mode == :binding)
38
+ IRT.log.pop_status
39
+ IRT.log.print_status unless resuming_context.irt_mode == :file
40
+ IRB.conf[:MAIN_CONTEXT] = resuming_context
41
+ IRT.log.add_hunk
42
+ end
43
+
44
+ private
45
+
46
+ # used for open the last file for editing
47
+ def set_binding_file_pointers(context)
48
+ caller.each do |c|
49
+ file, line = c.sub(/:in .*$/,'').split(':', 2)
50
+ next if File.expand_path(file).match(/^#{IRT.lib_path}/) # exclude irt internal callers
51
+ context.binding_file = file
52
+ context.binding_line_no = line
53
+ break
54
+ end
55
+ end
56
+
57
+
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irt
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 1
10
+ version: 1.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Domizio Demichelis
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-29 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: differ
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 1
34
+ version: 0.1.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: colorer
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ - 7
49
+ - 0
50
+ version: 0.7.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: prompter
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 25
62
+ segments:
63
+ - 0
64
+ - 1
65
+ - 1
66
+ version: 0.1.1
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: fastri
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 81
78
+ segments:
79
+ - 0
80
+ - 3
81
+ - 1
82
+ - 1
83
+ version: 0.3.1.1
84
+ type: :runtime
85
+ version_requirements: *id004
86
+ description: If you use IRT in place of irb or rails console, you will have more tools that will make your life a lot easier.
87
+ email: dd.nexus@gmail.com
88
+ executables:
89
+ - irt
90
+ - irt_irb
91
+ - irt_rails2
92
+ extensions: []
93
+
94
+ extra_rdoc_files: []
95
+
96
+ files:
97
+ - .gitignore
98
+ - LICENSE
99
+ - README.markdown
100
+ - Rakefile
101
+ - VERSION
102
+ - bin/irt
103
+ - bin/irt_irb
104
+ - bin/irt_rails2
105
+ - goodies/nano/README
106
+ - goodies/nano/irt.nanorc
107
+ - goodies/vi/README
108
+ - irt.gemspec
109
+ - irtrc
110
+ - lib/irt.rb
111
+ - lib/irt/commands/core.rb
112
+ - lib/irt/commands/help.rb
113
+ - lib/irt/commands/log.rb
114
+ - lib/irt/commands/ri.rb
115
+ - lib/irt/commands/system.rb
116
+ - lib/irt/commands/test.rb
117
+ - lib/irt/differ.rb
118
+ - lib/irt/directives.rb
119
+ - lib/irt/directives/test.rb
120
+ - lib/irt/extensions/irb.rb
121
+ - lib/irt/extensions/irb/commands.rb
122
+ - lib/irt/extensions/irb/context.rb
123
+ - lib/irt/extensions/kernel.rb
124
+ - lib/irt/extensions/method.rb
125
+ - lib/irt/extensions/object.rb
126
+ - lib/irt/hunks.rb
127
+ - lib/irt/init.rb
128
+ - lib/irt/log.rb
129
+ - lib/irt/session.rb
130
+ has_rdoc: true
131
+ homepage: http://github.com/ddnexus/irt
132
+ licenses: []
133
+
134
+ post_install_message:
135
+ rdoc_options:
136
+ - --charset=UTF-8
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 3
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ hash: 23
154
+ segments:
155
+ - 1
156
+ - 3
157
+ - 6
158
+ version: 1.3.6
159
+ requirements: []
160
+
161
+ rubyforge_project:
162
+ rubygems_version: 1.3.7
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: Interactive Ruby Tools - Improved irb and rails console with a lot of easy and powerful tools.
166
+ test_files: []
167
+