irbtools 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,9 @@
1
- 0.7.1
1
+ 0.7.3
2
+ * refactored file structure and added new Irbtools.add_lib method
3
+ * load railsrc if executed with rails and Irbtools.railsrc is set
4
+ * more little fixes
5
+
6
+ 0.7.2
2
7
  * fixed Rails 3 bug
3
8
  * added boson gem (command repository)
4
9
  * remember history when resetting or switching ruby version
data/README.rdoc CHANGED
@@ -23,11 +23,9 @@ If it does not exist, just create a new one.
23
23
  It's possible to modify, which libraries get loaded:
24
24
 
25
25
  require 'irbtools/configure'
26
- # here you can edit the Irbtools.libs array
26
+ # here you can edit the <tt>Irbtools.libs</tt> array or add libraries inclusive load callbacks with <tt>Irbtools.add_library</tt>
27
27
  Irbtools.init
28
28
 
29
- You could also just read and copy the irbtools/configure.rb and irbtools.rb source files, tweak them and use them directly as <tt>.irbrc</tt> ;)
30
-
31
29
  == Features
32
30
 
33
31
  See http://rbjl.net/40-irbtools-release-the-power-of-irb or read the commented source file: lib/irbtools.rb
data/Rakefile CHANGED
@@ -18,7 +18,6 @@ begin
18
18
  gem.add_dependency 'g'
19
19
  gem.add_dependency 'clipboard'
20
20
  gem.add_dependency 'guessmethod'
21
- # gem.add_dependency 'drx'
22
21
  gem.add_dependency 'interactive_editor'
23
22
  gem.add_dependency 'coderay'
24
23
  gem.add_dependency 'boson'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.7.3
data/irbtools.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{irbtools}
8
- s.version = "0.7.2"
8
+ s.version = "0.7.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jan Lelis"]
12
- s.date = %q{2010-10-07}
12
+ s.date = %q{2010-10-08}
13
13
  s.description = %q{irbtools is a meta gem which installs some useful irb gems and configures your irb. Simply put a require 'irbtools' in the .irbrc file in your home directory.}
14
14
  s.email = %q{mail@janlelis.de}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,9 @@ Gem::Specification.new do |s|
27
27
  "irbtools.gemspec",
28
28
  "lib/irbtools.rb",
29
29
  "lib/irbtools/configure.rb",
30
+ "lib/irbtools/general.rb",
31
+ "lib/irbtools/libraries.rb",
32
+ "lib/irbtools/workarounds.rb",
30
33
  "screenshots/examples1.png",
31
34
  "screenshots/examples2.png"
32
35
  ]
data/lib/irbtools.rb CHANGED
@@ -8,69 +8,14 @@ require File.expand_path('irbtools/configure', File.dirname(__FILE__) )
8
8
 
9
9
  # # # # #
10
10
  # load libraries
11
- Irbtools.libs.each{ |lib|
11
+ remember_verbose_and_debug = $VERBOSE, $DEBUG
12
+ $VERBOSE = $DEBUG = false
13
+
14
+ Irbtools.libraries.each{ |lib|
12
15
  begin
13
- require lib # &&
14
- case lib
15
-
16
- when 'wirble'
17
- Wirble.init
18
- Wirble.colorize unless OS.windows?
19
-
20
- when 'hirb'
21
- Hirb::View.enable
22
-
23
- when 'fileutils'
24
- include FileUtils::Verbose
25
-
26
- # patch cd so that it also shows the current directory
27
- def cd(path = '/', *args)
28
- FileUtils::Verbose.cd path, *args
29
- ls
30
- end
31
-
32
- when 'clipboard'
33
- # copies the clipboard
34
- def copy(str)
35
- Clipboard.copy(str)
36
- end
37
-
38
- # pastes the clipboard
39
- def paste
40
- Clipboard.paste
41
- end
42
-
43
- # copies everything you have entered in this irb session
44
- def copy_input
45
- copy session_history
46
- "The session input history has been copied to the clipboard."
47
- end
48
- alias copy_session_input copy_input
49
-
50
- # copies the output of all irb commands in this irb session
51
- def copy_output
52
- copy context.instance_variable_get(:@eval_history_values).inspect.gsub(/^\d+ (.*)/, '\1')
53
- "The session output history has been copied to the clipboard."
54
- end
55
- alias copy_session_output copy_output
56
-
57
-
58
- when 'coderay'
59
- # syntax highlight a string
60
- def colorize(string)
61
- puts CodeRay.scan( string, :ruby ).term
62
- end
63
-
64
- # syntax highlight a file
65
- def ray(path)
66
- puts CodeRay.scan( File.read(path), :ruby ).term
67
- end
68
-
69
- when 'boson'
70
- undef :install if respond_to?( :install, true )
71
- Boson.start :verbose => false
16
+ require lib.to_s
72
17
 
73
- end
18
+ Irbtools.send :library_loaded, lib
74
19
 
75
20
  rescue LoadError => err
76
21
  if err.to_s =~ /irb_rocket/ && RubyEngine.mri?
@@ -82,76 +27,11 @@ You can install it with: gem install irb_rocket --source http://merbi.st"
82
27
  end
83
28
  }
84
29
 
30
+ $VERBOSE, $DEBUG = remember_verbose_and_debug
31
+
85
32
  # # # # #
86
33
  # general shortcuts & helper methods
87
-
88
- # shows the contents of your current directory (more such commands available by FileUtils)
89
- def ls(path='.')
90
- Dir[ File.join( path, '*' )].map{|res| res =~ /^#{path}\/?/; $' }
91
- end
92
- alias dir ls
93
-
94
- # read file contents (also see ray for ruby source files ;) )
95
- def cat(path)
96
- File.read path
97
- end
98
-
99
- # allows concise syntax like rq:mathn
100
- def rq(lib)
101
- require lib.to_s
102
- end
103
-
104
- # returns the last lines, needed for some copy_ methods
105
- def session_history(number_of_lines = context.instance_variable_get(:@line_no) )
106
- Readline::HISTORY.entries[-number_of_lines...-1]*"\n"
107
- end
108
-
109
- # restart irb
110
- def reset!
111
- at_exit { exec$0 } # remember history
112
- exit
113
- end
114
-
115
- def ruby_version(which = nil)
116
- # test if installed
117
- unless `rvm -v` =~ /Seguin/
118
- raise 'Ruby Version Manager must be installed to use this command'
119
- end
120
-
121
- # show rubies if called without options
122
- if !which
123
- puts 'Availabe Rubies: ' +
124
- `rvm list`.scan( /^(?: |=>) (.*) \[/ )*", "
125
- return
126
- end
127
-
128
- # get irb suffix
129
- rv = `rvm use #{which}` # e.g. => "\ninfo: Using ruby 1.9.2 p0\n"
130
- # it does not change the ruby for the current user
131
- rv =~ /^.*Using(.*)\n/
132
-
133
- # if ruby is found, start it
134
- if $1
135
- ruby_name = File.split( $1 )[-1].tr(' ', '-')
136
- irbname = $0 + '-' + ruby_name# + '@global'
137
- at_exit { exec irbname } # remember history
138
- exit
139
- else
140
- puts "Sorry, that Ruby version could not be found."
141
- end
142
- end
143
- alias use ruby_version
144
-
145
- # load debugger, inspired by rdp
146
- def debuger
147
- begin
148
- require 'ruby-debug'
149
- debugger
150
- rescue LoadError => e
151
- throw "Sorry, unable to load ruby-debug gem for debugger: #{e}"
152
- end
153
- end
154
-
34
+ require File.expand_path('irbtools/general', File.dirname(__FILE__) )
155
35
 
156
36
  # # # # #
157
37
  # irb options
@@ -173,54 +53,21 @@ IRB.conf[:PROMPT_MODE] = :IRBTOOLS
173
53
 
174
54
  # # # # #
175
55
  # misc
176
- Zucker.more_aliases! # RubyVersion --> RV, RubyEngine --> RE
56
+ Object.const_set 'RV', RubyVersion rescue nil
57
+ Object.const_set 'RE', RubyEngine rescue nil
58
+
59
+ # # # # #
60
+ # load rails.rc
61
+ begin
62
+ if ( ENV['RAILS_ENV'] || defined? Rails ) && Irbtools.railsrc
63
+ load File.expand_path( Irbtools.railsrc )
64
+ end
65
+ rescue
66
+ end
177
67
 
178
68
  # # # # #
179
69
  # workarounds
180
-
181
- # irb_rocket stdout problems
182
- if IRB.const_defined? :CaptureIO
183
- module IRB
184
- class CaptureIO
185
- def self.streams
186
- {
187
- :stdout => @@current_capture.instance_variable_get( :@out ),
188
- :stderr => @@current_capture.instance_variable_get( :@err ),
189
- }
190
- end
191
-
192
- alias original_capture capture
193
- def capture(&block)
194
- @@current_capture = self
195
- original_capture &block
196
- end
197
- end
198
- end
199
-
200
- # patch method using stdout
201
- module Kernel
202
- alias exec_unpatched exec
203
- def exec(*args)
204
- STDOUT.reopen(IRB::CaptureIO.streams[:stdout])
205
- STDERR.reopen(IRB::CaptureIO.streams[:stderr])
206
- exec_unpatched *args
207
- end
208
- end
209
-
210
- if Object.const_defined? :InteractiveEditor
211
- InteractiveEditor::Editors.class_eval do
212
- editors = %w[vi vim emacs nano mate ed]
213
- editors.each{ |editor|
214
- alias_for editor, editor_unpatched = ( editor + '_unpatched' ).to_sym
215
- define_method editor do
216
- STDOUT.reopen(IRB::CaptureIO.streams[:stdout])
217
- STDERR.reopen(IRB::CaptureIO.streams[:stderr])
218
- send editor_unpatched
219
- end
220
- }
221
- end
222
- end
223
- end
70
+ require File.expand_path('irbtools/workarounds', File.dirname(__FILE__) )
224
71
 
225
72
  # # # # #
226
73
  # done :)
@@ -9,52 +9,64 @@ begin
9
9
  require 'zucker/alias_for'
10
10
  require 'zucker/env' # Info, OS, RubyVersion, RubyEngine
11
11
  rescue LoadError
12
- puts "The irbtools couldn't load, because the zucker gem is not available"
13
- else
14
- # suggested libraries
15
- module Irbtools
16
- @libs = ['rubygems',
17
- 'wirble', # colors
18
- 'hirb', # active record tables
19
- 'fileutils', # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
20
- 'zucker/debug', # nice debug printing (q, o, c, .m, .d)
21
- 'ap', # nice debug printing (ap)
22
- 'yaml', # nice debug printing (y)
23
- 'g', # nice debug printing (g) - MacOS only :/
24
- 'clipboard', # easy clipboard access (copy & paste)
25
- 'guessmethod', # automatically correct typos (method_missing hook)
26
- # 'drx', # nice tk object inspector (.see) [not included because it fails to install out of the box on lots of systems]
27
- 'interactive_editor', # lets you open vim (or your favourite editor), hack something, save it, and it's loaded in the current irb session
28
- 'coderay', # some nice colorful display ;)
29
- 'boson', # IRB commands repository (which also works for the shell!)
30
- 'irb_rocket', # put result as comment instead of a new line!
31
- # 'zucker/all' # see rubyzucker.info
32
- ]
33
-
34
- if OS.windows?
35
- @libs -= %w[irb_rocket coderay]
36
- end
37
-
38
- unless OS.mac?
39
- @libs -= %w[g]
40
- end
41
-
42
- if RubyVersion.is? 1.9
43
- @libs -= %w[guessmethod]
44
- end
45
-
46
- class << self
47
- def libs
48
- @libs
49
- end
50
- aliases_for :libs, :gems, :libraries
51
-
52
- def init
53
- require File.expand_path( '../irbtools.rb', File.dirname(__FILE__) )
54
- end
55
- end
56
- VERSION = File.read File.expand_path( '../../VERSION', File.dirname(__FILE__) )
57
- end#module
12
+ raise "Sorry, the irbtools couldn't load, because the zucker gem is not available"
58
13
  end
59
14
 
15
+ # # # # #
16
+ # define module methods
17
+ module Irbtools
18
+ @lib_hooks = Hash.new{|h,k| h[k] = [] }
19
+ @libs = %w[rubygems]
20
+ @railsrc = '~/.railsrc'
21
+
22
+ class << self
23
+ def libraries
24
+ @libs
25
+ end
26
+ aliases_for :libraries, :gems, :libs
27
+
28
+ def libraries=(value)
29
+ @libs = value
30
+ end
31
+ aliases_for :'libraries=', :'gems=', :'libs='
32
+
33
+ def add_library(lib, &block)
34
+ @libs << lib.to_s unless @libs.include? lib.to_s
35
+ @lib_hooks[lib.to_s] << block if block_given?
36
+ end
37
+ aliases_for :add_library, :add_lib, :add_gem
38
+
39
+ def remove_library(lib)
40
+ @libs.delete lib.to_s
41
+ @lib_hooks.delete lib.to_s
42
+ end
43
+ aliases_for :remove_library, :remove_lib, :remove_gem
44
+
45
+ def railsrc
46
+ @railsrc
47
+ end
48
+
49
+ def railsrc=(path)
50
+ @railsrc = path
51
+ end
52
+
53
+ def library_loaded(lib)
54
+ @lib_hooks[lib.to_s].each{ |hook| hook.call }
55
+ end
56
+ private :library_loaded
57
+
58
+ def init
59
+ require File.expand_path( '../irbtools.rb', File.dirname(__FILE__) )
60
+ end
61
+ alias start init
62
+ end
63
+
64
+ VERSION = File.read File.expand_path( '../../VERSION', File.dirname(__FILE__) )
65
+ end
66
+
67
+ # # # # #
68
+ # libraries
69
+ require File.expand_path( 'libraries.rb', File.dirname(__FILE__) )
70
+
60
71
  # J-_-L
72
+
@@ -0,0 +1,66 @@
1
+ # shows the contents of your current directory (more such commands available by FileUtils)
2
+ def ls(path='.')
3
+ Dir[ File.join( path, '*' )].map{|res| res =~ /^#{path}\/?/; $' }
4
+ end
5
+ alias dir ls
6
+
7
+ # read file contents (also see ray for ruby source files ;) )
8
+ def cat(path)
9
+ File.read path
10
+ end
11
+
12
+ # allows concise syntax like rq:mathn
13
+ def rq(lib)
14
+ require lib.to_s
15
+ end
16
+
17
+ # returns the last lines, needed for some copy_ methods
18
+ def session_history(number_of_lines = context.instance_variable_get(:@line_no) )
19
+ Readline::HISTORY.entries[-number_of_lines...-1]*"\n"
20
+ end
21
+
22
+ # restart irb
23
+ def reset!
24
+ at_exit { exec$0 } # remember history
25
+ exit
26
+ end
27
+
28
+ def ruby_version(which = nil)
29
+ # test if installed
30
+ unless `rvm -v` =~ /Seguin/
31
+ raise 'Ruby Version Manager must be installed to use this command'
32
+ end
33
+
34
+ # show rubies if called without options
35
+ if !which
36
+ puts 'Availabe Rubies: ' +
37
+ `rvm list`.scan( /^(?: |=>) (.*) \[/ )*", "
38
+ return
39
+ end
40
+
41
+ # get irb suffix
42
+ rv = `rvm use #{which}` # e.g. => "\ninfo: Using ruby 1.9.2 p0\n"
43
+ # it does not change the ruby for the current user
44
+ rv =~ /^.*Using(.*)\n/
45
+
46
+ # if ruby is found, start it
47
+ if $1
48
+ ruby_name = File.split( $1 )[-1].tr(' ', '-')
49
+ irbname = $0 + '-' + ruby_name# + '@global'
50
+ at_exit { exec irbname } # remember history
51
+ exit
52
+ else
53
+ puts "Sorry, that Ruby version could not be found."
54
+ end
55
+ end
56
+ alias use ruby_version
57
+
58
+ # load debugger, inspired by rdp
59
+ def dbg
60
+ begin
61
+ require 'ruby-debug'
62
+ debugger
63
+ rescue LoadError => e
64
+ throw "Sorry, unable to load ruby-debug gem for debugger: #{e}"
65
+ end
66
+ end
@@ -0,0 +1,94 @@
1
+ # encoding: utf-8
2
+
3
+ # # # # #
4
+ # require 'irbtools' in your .irbrc
5
+ # but you could also require 'irbtools/configure' and then call Irbtools.init to modify the loaded libraries
6
+ # see the README file for more information
7
+
8
+ Irbtools.add_library :wirble do # colors
9
+ Wirble.init
10
+ Wirble.colorize unless OS.windows?
11
+ end
12
+
13
+ Irbtools.add_library :hirb do # active record tables
14
+ Hirb::View.enable
15
+ end
16
+
17
+ Irbtools.add_library :fileutils do # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
18
+ include FileUtils::Verbose
19
+
20
+ # patch cd so that it also shows the current directory
21
+ def cd(path = '/', *args)
22
+ FileUtils::Verbose.cd path, *args
23
+ ls
24
+ end
25
+
26
+ end
27
+
28
+ Irbtools.add_library :coderay do
29
+ # syntax highlight a string
30
+ def colorize(string)
31
+ puts CodeRay.scan( string, :ruby ).term
32
+ end
33
+
34
+ # syntax highlight a file
35
+ def ray(path)
36
+ puts CodeRay.scan( File.read(path), :ruby ).term
37
+ end
38
+ end
39
+
40
+ Irbtools.add_library :clipboard do # access the clipboard
41
+ # copies the clipboard
42
+ def copy(str)
43
+ Clipboard.copy(str)
44
+ end
45
+
46
+ # pastes the clipboard
47
+ def paste
48
+ Clipboard.paste
49
+ end
50
+
51
+ # copies everything you have entered in this irb session
52
+ def copy_input
53
+ copy session_history
54
+ "The session input history has been copied to the clipboard."
55
+ end
56
+ alias copy_session_input copy_input
57
+
58
+ # copies the output of all irb commands in this irb session
59
+ def copy_output
60
+ copy context.instance_variable_get(:@eval_history_values).inspect.gsub(/^\d+ (.*)/, '\1')
61
+ "The session output history has been copied to the clipboard."
62
+ end
63
+ alias copy_session_output copy_output
64
+ end
65
+
66
+ Irbtools.add_library 'zucker/debug' # nice debug printing (q, o, c, .m, .d)
67
+ Irbtools.add_library 'ap' # nice debug printing (ap)
68
+ Irbtools.add_library 'yaml' # nice debug printing (y)
69
+ Irbtools.add_library 'g' # nice debug printing (g) - MacOS only :/
70
+ Irbtools.add_library 'guessmethod' # automatically correct typos (method_missing hook)
71
+ Irbtools.add_library 'interactive_editor' # lets you open vim (or your favourite editor), hack something, save it, and it's loaded in the current irb session
72
+ Irbtools.add_library 'irb_rocket' # put result as comment instead of a new line!
73
+ #Irbtools.add_library 'zucker/all' # see rubyzucker.info
74
+
75
+ Irbtools.add_library :boson do
76
+ undef :install if respond_to?( :install, true )
77
+ Boson.start :verbose => false
78
+ end
79
+
80
+ # remove failing/not needed libs
81
+ if OS.windows?
82
+ Irbtools.libraries -= %w[irb_rocket coderay]
83
+ end
84
+
85
+ unless OS.mac?
86
+ Irbtools.libraries -= %w[g]
87
+ end
88
+
89
+ if RubyVersion.is? 1.9
90
+ Irbtools.libraries -= %w[guessmethod]
91
+ end
92
+
93
+ # J-_-L
94
+
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ # # # # #
4
+ # require 'irbtools' in your .irbrc
5
+ # but you could also require 'irbtools/configure' and then call Irbtools.init to modify the loaded libraries
6
+ # see the README file for more information
7
+
8
+ # irb_rocket stdout problems
9
+ if IRB.const_defined? :CaptureIO
10
+ module IRB
11
+ class CaptureIO
12
+ def self.streams
13
+ {
14
+ :stdout => @@current_capture.instance_variable_get( :@out ),
15
+ :stderr => @@current_capture.instance_variable_get( :@err ),
16
+ }
17
+ end
18
+
19
+ alias original_capture capture
20
+ def capture(&block)
21
+ @@current_capture = self
22
+ original_capture &block
23
+ end
24
+ end
25
+ end
26
+
27
+ # patch methods using stdout
28
+ module Kernel
29
+ private
30
+
31
+ alias exec_unpatched exec
32
+ def exec(*args)
33
+ STDOUT.reopen(IRB::CaptureIO.streams[:stdout])
34
+ STDERR.reopen(IRB::CaptureIO.streams[:stderr])
35
+ exec_unpatched *args
36
+ end
37
+ end
38
+
39
+ alias dbg_unpatched dbg
40
+ def dbg
41
+ STDOUT.reopen(IRB::CaptureIO.streams[:stdout])
42
+ STDERR.reopen(IRB::CaptureIO.streams[:stderr])
43
+ dbg_unpatched
44
+ end
45
+
46
+ if Object.const_defined? :InteractiveEditor
47
+ InteractiveEditor::Editors.class_eval do
48
+ editors = %w[vi vim emacs nano mate ed]
49
+ editors.each{ |editor|
50
+ alias_for editor, editor_unpatched = ( editor + '_unpatched' ).to_sym
51
+ define_method editor do
52
+ STDOUT.reopen(IRB::CaptureIO.streams[:stdout])
53
+ STDERR.reopen(IRB::CaptureIO.streams[:stderr])
54
+ send editor_unpatched
55
+ end
56
+ }
57
+ end
58
+ end
59
+ end
60
+
61
+ # J-_-L
62
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irbtools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 2
10
- version: 0.7.2
9
+ - 3
10
+ version: 0.7.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jan Lelis
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-07 00:00:00 +02:00
18
+ date: 2010-10-08 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -178,6 +178,9 @@ files:
178
178
  - irbtools.gemspec
179
179
  - lib/irbtools.rb
180
180
  - lib/irbtools/configure.rb
181
+ - lib/irbtools/general.rb
182
+ - lib/irbtools/libraries.rb
183
+ - lib/irbtools/workarounds.rb
181
184
  - screenshots/examples1.png
182
185
  - screenshots/examples2.png
183
186
  has_rdoc: true