irbtools 0.8.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 1.0.0
2
+ * gemify general helpers/rvm stuff ("every_day_irb", "rvm_loader")
3
+ * 6 different loading schemas: start, thread, autoload, sub_session, late, late_thread
4
+ * load almost every feature via threads
5
+ * don't use zucker/alias_for, autload zucker/env (except zucker/os) for performance reasons
6
+ * add irbtools/minimal mode for starting Irbtools without the default set of libraries
7
+ * replace RV and RE with rv and re
8
+
1
9
  0.8.8
2
10
  * fix 0.8.7 file permissions
3
11
  * add methodfinder gem
@@ -1,20 +1,17 @@
1
1
  = irbtools
2
-
3
- This is a meta gem which installs some useful irb gems and configures your irb.
2
+ This is a meta gem that installs useful irb gems and configures your irb. It has a modular structure and supports multiple library-loading mechanisms, e.g. via <tt>autoload</tt> or threads.
4
3
 
5
4
  == Setup
6
-
7
5
  gem install irbtools
8
6
 
9
- * On Linux, you also need +xclip+: sudo <tt>apt-get install xclip</tt>
10
- * On Windows, you need ansicon[https://github.com/adoxa/ansicon]
7
+ * On Linux, you need +xclip+ or +xsel+ to use the clipboard: sudo <tt>apt-get install xclip</tt>
8
+ * On Windows, you need ansicon[https://github.com/adoxa/ansicon] to enjoy all the colors
11
9
  * On MacOS, you will need growl, if you want to use the +g+ gem.
12
10
 
13
11
  === Wrong display widths?
14
12
  When using double-width unicode chars, you should need to pass the <tt>:east_asian_width = true</tt> when starting <tt>FancyIrb</tt>. It is deactivated because of performance issues.
15
13
 
16
14
  == Usage
17
-
18
15
  To use it, put the following in your <tt>~/.irbrc</tt> file (this file is loaded every time you start an irb):
19
16
 
20
17
  require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
@@ -27,36 +24,52 @@ It's possible to modify, which libraries get loaded:
27
24
  # don't require 'irbtools'
28
25
  require 'irbtools/configure'
29
26
  # here you can modify which libraries get loaded (see below)
30
- Irbtools.init
27
+ Irbtools.start
28
+
29
+ You can also deactivate the loading of the complete default set of irbtools libraries by using <tt>require 'irbtools/minimal'</tt> instead of <tt>configure</tt>. You need to use the below methods for adding libraries in this case, or it won't modify anything of your irb ;).
31
30
 
32
31
  === Rails notes
32
+ To use irbtools within the rails console, you will have to add irbtools to your Gemfile <b>in this way:</b> (or there will be some bundler double require issues..)
33
33
 
34
- To use irbtools within the rails console, you will have to add irbtools to your Gemfile.
34
+ gem 'irbtools', :require => 'irbtools/configure'
35
35
 
36
36
  You can put Rails specific configuration in a <tt>~/.railsrc</tt> file which gets loaded only in Rails environments.
37
37
 
38
38
  === How to load more or less libraries
39
-
40
39
  You have the following ways:
41
- * <tt>Irbtools.add_library(lib, in_proc = false, &block)</tt>
40
+ * <tt>Irbtools.add_library(lib, options_hash, &block)</tt>
42
41
  * <tt>Irbtools.remove_library(lib)</tt>
43
- * <tt>Irbtools.add_package(pkg)</tt>
44
- * <tt>Irbtools.remove_package(pkg)</tt>
45
42
 
46
- You can edit the <tt>Irbtools.libraries</tt> or <tt>Irbtools.libraries_in_proc</tt> directly, but when using the <tt>add_library</tt> method, you can apply a block which gets executed after the library is loaded.
43
+ The <tt>options_hash</tt> defines the way in which Irbtools loads the library. Following options are possible
44
+ * (no options)/<tt>:start</tt> - The library is required on startup before doing anything else
45
+ (before displaying the prompt)
46
+ * <tt>:thread => identifier</tt> - After loading everything else, the library is required in a thread (while continuing loading). You can choose any identifier, but if you take the same one for multiple libraries, they will be loaded in the same thread (in the order that you define)
47
+ * <tt>:late => true</tt> - The library is required just before showing the prompt (note: loading threads might still be in process)
48
+ * <tt>:late_thread => identifier</tt> - Same as <tt>:thread</tt>, but after loading late libraries.
49
+ * <tt>:sub_session => true</tt> - The library is loaded every time a sub-session starts (using <tt>IRB.conf[:IRB_RC]</tt>). In ripl[https://github.com/cldwalker/ripl], <tt>ripl-after_rc</tt> is used.
50
+ * <tt>:autoload => :Constant</tt> - Use Ruby's <tt>autoload</tt> feature. It loads the library as soon as the constant is encountered.
51
+
52
+ You can also apply a block that gets executed after the library is loaded (except for autoload, the code will executed on startup in this case).
53
+
54
+ When adding a new library, you should consider adding it via autoload, try loading it via thread if autoload is not suitable and fallback to some other method, if not via thread is not possible.
55
+
56
+ See the <tt>Irbtools.libraries</tt> hash for the current Irbtools configuration that actually will be used when calling <tt>Irbtools.start</tt>.
47
57
 
48
58
  ==== Packages
49
- <tt>Irbtools.packages</tt> are extension packs for Irbtools, e.g. {irbtools-more}[https://github.com/janlelis/irbtools-more].
59
+ There are irbtools extension packages, which can be modified via:
60
+ * <tt>Irbtools.add_package(pkg)</tt>
61
+ * <tt>Irbtools.remove_package(pkg)</tt>
50
62
 
51
- == Features
63
+ These packages add/modify the libraries to be loaded. For an example, see {irbtools-more}[https://github.com/janlelis/irbtools-more].
52
64
 
65
+ == Features
53
66
  See http://rbjl.net/40-irbtools-release-the-power-of-irb or read the commented source files.
54
67
 
55
68
  === Included gems and libraries
56
-
57
69
  * wirb[https://github.com/janlelis/wirb/] colorize output
58
70
  * hirb[http://tagaholic.me/2009/03/13/hirb-irb-on-the-good-stuff.html] (active record) tables and custom views for specific objects
59
71
  * fancy_irb[https://github.com/janlelis/fancy_irb] put result as comment and more colorization
72
+ * every_day_irb[https://github.com/janlelis/irbtools/tree/master/lib/every_day_irb.rb] helper methods that might be useful in every-day irb usage, e.g.: ls, cat, rq, rrq, ld, session_history, reset!, clear, dbg
60
73
  * clipboard[http://github.com/janlelis/clipboard] easy clipboard access (copy & paste)
61
74
  * interactive_editor[https://github.com/jberkel/interactive_editor] lets you open vim, hack something, and it gets loaded into the current session, also possible: yaml object editing
62
75
  * sketches[http://sketches.rubyforge.org/] another, more flexible "start editor and it gets loaded into your irb session" plugin
@@ -71,31 +84,24 @@ See http://rbjl.net/40-irbtools-release-the-power-of-irb or read the commented s
71
84
 
72
85
  * guessmethod[http://guessmethod.rubyforge.org/] automatically corrects typos (method_missing hook)
73
86
 
74
- === Helper methods
75
-
76
- See the source for a description. These methods are defined directly by irbtools. Each gem may add its own helper methods.
77
-
78
- *General*: <tt>ls, cat, rq, rrq/rerequire, ld, session_history, reset!, clear, use_ruby/use, rubies, use_gemset/gemset, gemsets, dbg</tt>
79
-
80
- *Clipboard*: <tt>copy, paste, copy_input, copy_output</tt>
81
-
82
- *CodeRay*: <tt>colorize, ray</tt>
83
-
84
87
  ==== RVM
85
-
86
88
  If you have RVM installed, you can switch your gemset or ruby with <tt>gemset</tt> and <tt>use</tt> (use <tt>gemsets</tt> and <tt>rubies</tt> to get a list). The gemset can be changed within the session, while changing ruby starts a new one. Please also note that you need to have installed irbtools for that ruby version. I recommend installing it in the <tt>global</tt> gemset.
87
89
 
88
- == Welcome message
90
+ == Hint: Faster start-up
89
91
 
90
- You can customize the welcome message with <tt>Irbtools.welcome_message=</tt>
92
+ You can get an about a second faster start-up time by changing the loading methods for wirb and fancy_irb to <tt>:thread</tt> (drawback: the hash rocket will not be used for the first result):
91
93
 
92
- == Planned features for 0.9.0 (next main version - probably coming in may 2011)
94
+ require 'irbtools/configure'
95
+ Irbtools.remove_library :wirb
96
+ Irbtools.remove_library :fancy_irb
97
+ Irbtools.add_library :wirb, :thread => -1 do Wirb.start end
98
+ Irbtools.add_library :fancy_irb, :thread => -1 do FancyIrb.start end
99
+ Irbtools.start
93
100
 
94
- * define flexibly, whether library should be loaded on start/on subsession or via autoload
95
- * faster loading
101
+ == Welcome message
102
+ The welcome message can be customized with <tt>Irbtools.welcome_message=</tt>
96
103
 
97
104
  == Copyright
98
-
99
105
  Copyright (c) 2010-2011 Jan Lelis, http://rbjl.net, released under the MIT license.
100
106
 
101
107
  J-_-L
data/Rakefile CHANGED
@@ -2,37 +2,37 @@ require 'rake'
2
2
  require 'rake/rdoctask'
3
3
  require 'fileutils'
4
4
 
5
- def gemspec
6
- @gemspec ||= eval(File.read('irbtools.gemspec'), binding, 'irbtools.gemspec')
5
+ def gemspec1
6
+ @gemspec1 ||= eval(File.read('irbtools.gemspec'), binding, 'irbtools.gemspec')
7
+ end
8
+
9
+ def gemspec2
10
+ @gemspec2 ||= eval(File.read('every_day_irb.gemspec'), binding, 'every_day_irb.gemspec')
7
11
  end
8
12
 
9
13
  desc "Build the gem"
10
14
  task :gem => :gemspec do
11
15
  sh "gem build irbtools.gemspec"
16
+ sh "gem build every_day_irb.gemspec"
12
17
  FileUtils.mkdir_p 'pkg'
13
- FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
18
+ FileUtils.mv "#{gemspec1.name}-#{gemspec1.version}.gem", 'pkg'
19
+ FileUtils.mv "#{gemspec2.name}-#{gemspec2.version}.gem", 'pkg'
14
20
  end
15
21
 
16
22
  desc "Install the gem locally (without docs)"
17
23
  task :install => :gem do
18
- sh %{gem install pkg/#{gemspec.name}-#{gemspec.version} --no-rdoc --no-ri}
24
+ sh %{gem install pkg/#{gemspec2.name}-#{gemspec2.version} --no-rdoc --no-ri}
25
+ sh %{gem install pkg/#{gemspec1.name}-#{gemspec1.version} --no-rdoc --no-ri}
19
26
  end
20
27
 
21
28
  desc "Generate the gemspec"
22
29
  task :generate do
23
- puts gemspec.to_ruby
30
+ puts gemspec1.to_ruby
31
+ puts gemspec2.to_ruby
24
32
  end
25
33
 
26
34
  desc "Validate the gemspec"
27
35
  task :gemspec do
28
- gemspec.validate
29
- end
30
-
31
- Rake::RDocTask.new do |rdoc|
32
- version = File.exist?('VERSION') ? File.read('VERSION').chomp : ""
33
-
34
- rdoc.rdoc_dir = 'doc'
35
- rdoc.title = "irbtools #{version}"
36
- rdoc.rdoc_files.include('README*')
37
- rdoc.rdoc_files.include('lib/**/*.rb')
36
+ gemspec1.validate
37
+ gemspec2.validate
38
38
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.8
1
+ 1.0.0
@@ -6,26 +6,27 @@ Gem::Specification.new do |s|
6
6
  s.version = File.read('VERSION').chomp
7
7
 
8
8
  s.authors = ["Jan Lelis"]
9
- s.date = %q{2011-03-28}
10
- s.summary = %q{irbtools is a meta gem which installs some useful irb gems and configures your irb.}
11
- 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.}
12
- s.email = %q{mail@janlelis.de}
9
+ s.summary = 'irbtools is a meta gem that installs useful irb gems and configures your irb.'
10
+ s.description = 'irbtools is a meta gem that installs useful irb gems and configures your irb. Simply put a require "irbtools" in the .irbrc file in your home directory.'
11
+ s.email = 'mail@janlelis.de'
13
12
  s.extra_rdoc_files = %w[LICENSE README.rdoc]
14
- s.files = Dir.glob(%w[lib/**/*.rb ]) + %w{VERSION CHANGELOG Rakefile irbtools.gemspec}
15
- s.homepage = %q{http://github.com/janlelis/irbtools}
13
+ s.files = %w[lib/irbtools.rb lib/irbtools/configure.rb lib/irbtools/libraries.rb lib/irbtools/minimal.rb VERSION CHANGELOG Rakefile irbtools.gemspec]
14
+ s.homepage = 'http://github.com/janlelis/irbtools'
16
15
  s.required_ruby_version = '>= 1.8.7'
17
16
 
18
17
  s.add_dependency %q<fancy_irb>, ">= 0.6.5"
19
- s.add_dependency %q<zucker>, ">= 9"
20
- s.add_dependency %q<hirb>, "~> 0.4.3"
21
- s.add_dependency %q<awesome_print>, "~> 0.3.2"
22
- s.add_dependency %q<clipboard>, ">= 0.9.7"
18
+ s.add_dependency %q<zucker>, ">= 10"
19
+ s.add_dependency %q<hirb>, "~> 0.4.5"
20
+ s.add_dependency %q<awesome_print>, "~> 0.4.0"
21
+ s.add_dependency %q<clipboard>, ">= 0.9.8"
23
22
  s.add_dependency %q<coderay>, "~> 0.9"
24
23
  s.add_dependency %q<boson>, ">= 0.3.3"
25
- s.add_dependency %q<wirb>, ">= 0.2.4"
24
+ s.add_dependency %q<wirb>, ">= 0.2.6"
26
25
  s.add_dependency %q<interactive_editor>, ">= 0.0.8"
27
26
  s.add_dependency %q<ori>, "~> 0.1.0"
28
27
  s.add_dependency %q<sketches>, ">= 0"
29
28
  s.add_dependency %q<g>, ">= 0"
30
- s.add_dependency %q<methodfinder>, ">= 1.2.1"
29
+ s.add_dependency %q<methodfinder>, ">= 1.2.3"
30
+ s.add_dependency %q<rvm_loader>, ">= 1.0.0"
31
+ s.add_dependency %q<every_day_irb>, ">= #{ s.version }"
31
32
  end
@@ -18,9 +18,7 @@ if defined?(IRB) || defined?(Ripl)
18
18
  }
19
19
 
20
20
  # # # # #
21
- # load libraries
22
-
23
- # load helper proc
21
+ # loading helper proc
24
22
  load_libraries_proc = proc{ |libs|
25
23
  remember_verbose_and_debug = $VERBOSE, $DEBUG
26
24
  $VERBOSE = $DEBUG = false
@@ -28,9 +26,7 @@ if defined?(IRB) || defined?(Ripl)
28
26
  libs.each{ |lib|
29
27
  begin
30
28
  require lib.to_s
31
-
32
29
  Irbtools.send :library_loaded, lib
33
-
34
30
  rescue LoadError => err
35
31
  warn "Couldn't load an irb library: #{err}"
36
32
  end
@@ -38,24 +34,21 @@ if defined?(IRB) || defined?(Ripl)
38
34
  $VERBOSE, $DEBUG = remember_verbose_and_debug
39
35
  }
40
36
 
41
- # load them :)
42
- load_libraries_proc[ Irbtools.libraries ]
43
-
44
- # load these each time a new sub irb starts (only if supported)
45
- original_irbrc_proc = IRB.conf[:IRB_RC]
46
- IRB.conf[:IRB_RC] = proc{
47
- load_libraries_proc[ Irbtools.libraries_in_proc ]
48
- original_irbrc_proc[ ] if original_irbrc_proc
49
- }
50
-
37
+ # # # # #
38
+ # load: start
39
+ load_libraries_proc[ Irbtools.libraries[:start] ]
51
40
 
52
41
  # # # # #
53
- # general shortcuts & helper methods
54
- require File.expand_path('irbtools/general', File.dirname(__FILE__) )
42
+ # load: autoload
43
+ Irbtools.libraries[:autoload].each{ |constant, lib_name, gem_name|
44
+ gem gem_name
45
+ autoload constant, lib_name
46
+ Irbtools.send :library_loaded, lib_name
47
+ }
55
48
 
56
49
  # # # # #
57
50
  # irb options
58
- unless defined? Ripl
51
+ unless defined?(Ripl) && Ripl.respond_to?(:started?) && Ripl.started?
59
52
  IRB.conf[:AUTO_INDENT] = true # simple auto indent
60
53
  IRB.conf[:EVAL_HISTORY] = 42424242424242424242 # creates the special __ variable
61
54
  IRB.conf[:SAVE_HISTORY] = 2000 # how many lines will go to ~/.irb_history
@@ -74,16 +67,11 @@ if defined?(IRB) || defined?(Ripl)
74
67
  end
75
68
 
76
69
  # # # # #
77
- # misc
78
-
79
- # add current directory to the load path
80
- $: << '.' if RubyVersion.is.at_least? '1.9.2'
81
-
82
- # shorter ruby info constants
83
- Object.const_set :RV, RubyVersion rescue nil
84
- Object.const_set :RE, RubyEngine rescue nil
70
+ # misc: add current directory to the load path
71
+ $: << '.' if RUBY_VERSION >= '1.9.2'
85
72
 
86
- # load rails.rc
73
+ # # # # #
74
+ # load: rails.rc
87
75
  begin
88
76
  if ( ENV['RAILS_ENV'] || defined? Rails ) && Irbtools.railsrc &&
89
77
  File.exist?( File.expand_path(Irbtools.railsrc) )
@@ -92,6 +80,42 @@ if defined?(IRB) || defined?(Ripl)
92
80
  rescue
93
81
  end
94
82
 
83
+ # # # # #
84
+ # load: sub-session / after_rc
85
+ if defined?(Ripl) && Ripl.respond_to?(:started?) && Ripl.started?
86
+ if defined? Ripl::AfterRc
87
+ Ripl.after_rcs += Irbtools.libraries[:sub_session]
88
+ elsif !Irbtools.libraries[:sub_session].empty?
89
+ warn "Couldn't load libraries in Irbtools.libraries[:sub_session]. Please install ripl-after_rc to use this feature in Ripl!"
90
+ end
91
+ else
92
+ original_irbrc_proc = IRB.conf[:IRB_RC]
93
+ IRB.conf[:IRB_RC] = proc{
94
+ load_libraries_proc[ Irbtools.libraries[:sub_session] ]
95
+ original_irbrc_proc[ ] if original_irbrc_proc
96
+ }
97
+ end
98
+
99
+ # # # # #
100
+ # load: threads
101
+ Irbtools.libraries[:thread].each{ |_,libs|
102
+ Thread.new do
103
+ load_libraries_proc[ libs ]
104
+ end
105
+ }
106
+
107
+ # # # # #
108
+ # load: late
109
+ load_libraries_proc[ Irbtools.libraries[:late] ]
110
+
111
+ # # # # #
112
+ # load: late_threads
113
+ Irbtools.libraries[:late_thread].each{ |_,libs|
114
+ Thread.new do
115
+ load_libraries_proc[ libs ]
116
+ end
117
+ }
118
+
95
119
  # # # # #
96
120
  # done :)
97
121
  if msg = Irbtools.welcome_message
@@ -5,23 +5,18 @@
5
5
  # but you could also require 'irbtools/configure' and then call Irbtools.init to modify the loaded libraries
6
6
  # see the README file for more information
7
7
 
8
- begin
9
- require 'zucker/alias_for'
10
- require 'zucker/env' # Info, OS, RubyVersion, RubyEngine
11
- rescue LoadError
12
- raise LoadError, "Sorry, the irbtools couldn't load, because the zucker gem is not available"
13
- end
14
-
15
8
  # # # # #
16
9
  # define module methods
17
10
  module Irbtools
11
+ VERSION = File.read( File.dirname(__FILE__) + '/../../VERSION' ).chomp
12
+
13
+ @libraries = { :start => [], :sub_session => [], :autoload => [], :thread => {}, :late => [], :late_thread => {} }
18
14
  @lib_hooks = Hash.new{|h,k| h[k] = [] }
19
- @libs = []
20
- @libs_in_proc = []
21
15
  @packages = []
22
16
  @railsrc = '~/.railsrc'
23
17
  @shell_name = File.split($0)[-1].upcase
24
18
  @welcome_message = "Welcome to #{ @shell_name }. You are using #{ RUBY_DESCRIPTION }. Have fun ;)"
19
+ @minimal ||= false
25
20
 
26
21
  class << self
27
22
  # message to display when starting. Set to nil to disable
@@ -30,39 +25,72 @@ module Irbtools
30
25
  # shell name (usually irb), retrieved from $0
31
26
  attr_reader :shell_name
32
27
 
33
- # lets you define the path to the irbrc or deactivate this feature with nil
28
+ # lets you define the path to the railsrc file or deactivate this feature with nil
34
29
  attr_accessor :railsrc
35
30
 
36
- # an array of the libraries which get loaded at start
37
- attr_accessor :libs
38
- aliases_for :libs, :libraries, :gems
39
- aliases_for :libs=, :libraries=, :gems=
31
+ # set this to true before loading this file to deactivate loading of default libraries
32
+ attr_accessor :minimal
40
33
 
41
- # an array of the libraries which get loaded everytime a new subirb starts (IRB.conf[:IRB_RC])
42
- attr_accessor :libs_in_proc
43
- aliases_for :libs_in_proc, :libraries_in_proc, :gems_in_proc
44
- aliases_for :libs_in_proc=, :libraries_in_proc=, :gems_in_proc=
34
+ # a hash of arrays of libraries that get loaded
35
+ # keys determine if lib is required, required on sub-session or autoloaded
36
+ attr_accessor :libraries
37
+ alias libs libraries
38
+ alias libs= libraries=
39
+ alias gems libraries
40
+ alias gems= libraries=
45
41
 
46
- # an array of extension packages which get loaded (e.g. irbtools-more)
42
+ # an array of extension packages that get loaded (e.g. irbtools-more)
47
43
  attr_accessor :packages
48
44
 
49
45
  # add a library. the block gets executed, when the library was loaded.
50
46
  # if the second param is true, it's hooked in into IRB.conf[:IRB_RC] instead of the start.
51
- def add_library(lib, in_proc = false, &block)
52
- libs = in_proc ? @libs_in_proc : @libs
53
- libs << lib.to_s unless libs.include? lib.to_s
54
-
55
- @lib_hooks[lib.to_s] << block if block_given?
47
+ def add_library(lib, options = {}, &block)
48
+ lib = lib.to_s
49
+
50
+ if constant = options[:autoload]
51
+ lib_path = File.split( lib ); lib_path.delete('.')
52
+ gem_name = lib_path[0] # assume that first dir in load dir is the gem name
53
+ if constant.is_a?(Array)
54
+ constant.each{ |single_constant|
55
+ @libraries[:autoload] << [single_constant, lib, gem_name]
56
+ }
57
+ else
58
+ @libraries[:autoload] << [constant, lib, gem_name]
59
+ end
60
+ elsif options[:after_rc]
61
+ @libraries[:after_rc] << lib
62
+ elsif which = options[:thread]
63
+ @libraries[:thread][which] ||= []
64
+ @libraries[:thread][which] << lib
65
+ elsif options[:late]
66
+ @libraries[:late] << lib
67
+ elsif which = options[:late_thread]
68
+ @libraries[:late_thread][which] ||= []
69
+ @libraries[:late_thread][which] << lib
70
+ else
71
+ @libraries[:start] << lib
72
+ end
73
+
74
+ @lib_hooks[lib] << block if block_given?
56
75
  end
57
- aliases_for :add_library, :add_lib, :add_gem
76
+ alias add_lib add_library
77
+ alias add_gem add_library
58
78
 
59
79
  # don't load a specific library
60
80
  def remove_library(lib)
61
- @libs.delete lib.to_s
62
- @libs_in_proc.delete lib.to_s
63
- @lib_hooks.delete lib.to_s
81
+ lib = lib.to_s
82
+
83
+ @libraries[:start].delete lib
84
+ @libraries[:sub_session].delete lib
85
+ @libraries[:autoload].reject!{|_,e,| e == lib }
86
+ @libraries[:thread].each{ |_,libs| libs.delete lib }
87
+ @libraries[:late].delete lib
88
+ @libraries[:late_thread].each{ |_,libs| libs.delete lib }
89
+
90
+ @lib_hooks.delete lib
64
91
  end
65
- aliases_for :remove_library, :remove_lib, :remove_gem
92
+ alias remove_lib remove_library
93
+ alias remove_gem remove_library
66
94
 
67
95
  # add extensions packages
68
96
  def add_package(pkg)
@@ -74,7 +102,6 @@ module Irbtools
74
102
  @packages.delete pkg.to_s
75
103
  end
76
104
 
77
-
78
105
  def library_loaded(lib) #:nodoc:
79
106
  @lib_hooks[lib.to_s].each{ |hook| hook.call }
80
107
  end
@@ -86,13 +113,11 @@ module Irbtools
86
113
  end
87
114
  alias start init
88
115
  end
89
-
90
- VERSION = ( File.read File.expand_path( '../../VERSION', File.dirname(__FILE__)) ).chomp
91
116
  end
92
117
 
93
118
  # # # # #
94
119
  # libraries
95
- require File.expand_path( 'libraries.rb', File.dirname(__FILE__) )
120
+ require File.expand_path( 'libraries.rb', File.dirname(__FILE__) ) unless Irbtools.minimal
96
121
 
97
122
  # J-_-L
98
123
 
@@ -1,22 +1,28 @@
1
1
  # encoding: utf-8
2
+ # default irbtools set of libraries, you can remove any you don't like via Irbtools.remove_library
2
3
 
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
4
+ # # # load via late
7
5
 
8
- # the order does matter
9
- Irbtools.add_library :wirb do # result colors
10
- Wirb.start unless OS.windows?
6
+ unless defined?(Ripl) && Ripl.respond_to?(:started?) && Ripl.started?
7
+ Irbtools.add_library :wirb, :late => true do # result colors, install ripl-color_result for ripl colorization
8
+ Wirb.start
9
+ end
10
+
11
+ Irbtools.add_library :fancy_irb, :late => true do # put result as comment instead of a new line and colorful errors/streams
12
+ FancyIrb.start
13
+ end
11
14
  end
12
- Irbtools.add_library 'wirb/wp' # ap alternative
13
15
 
14
16
 
15
- Irbtools.add_library :fancy_irb do # put result as comment instead of a new line and colorful errors/streams
16
- FancyIrb.start
17
- end
17
+ # # # load via late_thread
18
+
19
+ Irbtools.add_library 'wirb/wp', :late_thread => 10 # ap alternative (wp)
20
+
18
21
 
19
- Irbtools.add_library :fileutils do # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
22
+ # # # load via thread
23
+ # the :stdlib thread ensures proper loading of fileutils, yaml and tempfile
24
+
25
+ Irbtools.add_library :fileutils, :thread => :stdlib do # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
20
26
  include FileUtils::Verbose
21
27
 
22
28
  # patch cd so that it also shows the current directory
@@ -30,26 +36,89 @@ Irbtools.add_library :fileutils do # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
30
36
  return
31
37
  end
32
38
  end
33
- FileUtils.cd path
39
+ cd path
34
40
  @last_path = new_last_path
35
41
  ls
36
42
  end
43
+ end
44
+
45
+ # tables, menus...
46
+ Irbtools.add_library :hirb, :thread => :stdlib do
47
+ Hirb::View.enable
48
+ extend Hirb::Console
49
+ Hirb::View.formatter.add_view 'Object', :ancestor => true, :options => { :unicode => true } # unicode tables
50
+ end
51
+
52
+ # command framework
53
+ Irbtools.add_library :boson, :thread => :stdlib do
54
+ undef install if respond_to?( :install, true )
55
+ undef menu if respond_to?( :menu, true )
56
+ Boson.start :verbose => false
57
+ end
58
+
59
+ # ls, cat, rq, rrq, ld, session_history, reset!, clear, dbg, ...
60
+ Irbtools.add_library 'every_day_irb', :thread => 10
61
+
62
+ # nice debug printing (q, o, c, .m, .d)
63
+ Irbtools.add_library 'zucker/debug', :thread => 20
64
+
65
+ # nice debug printing (ap)
66
+ Irbtools.add_library 'ap', :thread => 30
67
+
68
+ # nice debug printing (g)
69
+ Irbtools.add_library 'g', :thread => 40 if RbConfig::CONFIG['host_os'] =~ /mac|darwin/
70
+
71
+ # 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 'interactive_editor', :thread => :stdlib
73
+
74
+ # another, more flexible "start editor and it gets loaded into your irb session" plugin
75
+ Irbtools.add_library 'sketches', :thread => :stdlib
76
+
77
+ # object oriented ri method
78
+ Irbtools.add_library :ori, :thread => 50 do
79
+ class Object
80
+ # patch ori to also allow shell-like "Array#slice" syntax
81
+ def ri(*args)
82
+ if args[0] &&
83
+ self == TOPLEVEL_BINDING.eval('self') &&
84
+ args[0] =~ /\A(.*)(?:#|\.)(.*)\Z/
85
+ begin
86
+ klass = Object.const_get $1
87
+ klass.ri $2
88
+ rescue
89
+ super
90
+ end
91
+ else
92
+ super
93
+ end
94
+ end
95
+ end
96
+ end
97
+
37
98
 
99
+ # # # load via autoload
100
+
101
+ # useful information pseudo-constants
102
+ Irbtools.add_library 'zucker/env', :autoload => [:RubyVersion, :RubyEngine, :Info, :OS] do
103
+ def rv() RubyVersion end unless defined? rv
104
+ def re() RubyEngine end unless defined? re
38
105
  end
39
106
 
40
- Irbtools.add_library :coderay do
41
- # syntax highlight a string
107
+ # syntax highlight
108
+ Irbtools.add_library :coderay, :autoload => :CodeRay do
109
+ # ...a string
42
110
  def colorize(string)
43
111
  puts CodeRay.scan( string, :ruby ).term
44
112
  end
45
113
 
46
- # syntax highlight a file
114
+ # ...a file
47
115
  def ray(path)
48
116
  print CodeRay.scan( File.read(path), :ruby ).term
49
117
  end
50
118
  end
51
119
 
52
- Irbtools.add_library :clipboard do # access the clipboard
120
+ # access the clipboard
121
+ Irbtools.add_library :clipboard, :autoload => :Clipboard do
53
122
  # copies the clipboard
54
123
  def copy(str)
55
124
  Clipboard.copy(str)
@@ -75,65 +144,65 @@ Irbtools.add_library :clipboard do # access the clipboard
75
144
  alias copy_session_output copy_output
76
145
  end
77
146
 
78
- Irbtools.add_library 'zucker/debug' # nice debug printing (q, o, c, .m, .d)
79
- Irbtools.add_library 'ap' # nice debug printing (ap)
80
- Irbtools.add_library 'yaml' # nice debug printing (y)
81
- Irbtools.add_library 'g' # nice debug printing (g) - MacOS only :/
82
- #Irbtools.add_library 'guessmethod', true # automatically correct typos (method_missing hook)
83
- 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
84
- Irbtools.add_library 'sketches' # another, more flexible "start editor and it gets loaded into your irb session" plugin
85
-
86
- Irbtools.add_library :boson do
87
- undef :install if respond_to?( :install, true )
88
- Boson.start :verbose => false
147
+ # small-talk like method finder
148
+ Irbtools.add_library :methodfinder, :autoload => :MethodFinder do
149
+ MethodFinder::INSTANCE_METHOD_BLACKLIST[:Object] += [:ri, :vi, :vim, :emacs, :nano, :mate, :mvim, :ed, :sketch]
150
+
151
+ def mf(*args, &block)
152
+ args.empty? ? MethodFinder : MethodFinder.find(*args, &block)
153
+ end
89
154
  end
90
155
 
91
- Irbtools.add_library :hirb do
92
- Hirb::View.enable
93
- extend Hirb::Console
94
- Hirb::View.formatter.add_view 'Object', :ancestor => true, :options => { :unicode => true } # unicode tables
95
- end
156
+ # rvm helpers
157
+ Irbtools.add_library 'rvm_loader', :autoload => :RVM do
158
+ def rubies
159
+ RVM.current.list_strings
160
+ end
96
161
 
97
- Irbtools.add_library :ori do
98
- class Object
99
- # patch ori to also allow shell-like "Array#slice" syntax
100
- def ri(*args)
101
- if args[0] &&
102
- self == TOPLEVEL_BINDING.eval('self') &&
103
- args[0] =~ /\A(.*)(?:#|\.)(.*)\Z/
104
- begin
105
- klass = Object.const_get $1
106
- klass.ri $2
107
- rescue
108
- super
162
+ def use(which = nil) # TODO with gemsets?
163
+ # show current ruby if called without options
164
+ if !which
165
+ return RVM.current.environment_name[/^.*@|.*$/].chomp('@')
166
+ end
167
+
168
+ # start ruby :)
169
+ begin
170
+ RVM.use! which.to_s
171
+ rescue RVM::IncompatibleRubyError => err
172
+ err.message =~ /requires (.*?) \(/
173
+ rubies = RVM.current.list_strings
174
+ if rubies.include? $1
175
+ # remember history...
176
+ run_irb = proc{ exec "#{ $1 } -S #{ $0 }" }
177
+ if defined?(Ripl) && Ripl.respond_to?(:started?) && Ripl.started?
178
+ Ripl.shell.write_history if Ripl.shell.respond_to? :write_history
179
+ run_irb.call
180
+ else
181
+ at_exit(&run_irb)
182
+ exit
109
183
  end
110
184
  else
111
- super
185
+ warn "Sorry, that Ruby version could not be found (see rubies)!"
112
186
  end
113
187
  end
114
188
  end
115
- end
189
+ alias use_ruby use
116
190
 
117
- Irbtools.add_library :methodfinder do
118
- MethodFinder::INSTANCE_METHOD_BLACKLIST[:Object] += [:ri, :vi, :vim, :emacs, :nano, :mate, :mvim, :ed, :sketch]
119
-
120
- def mf(*args, &block)
121
- args.empty? ? MethodFinder : MethodFinder.find(*args, &block)
191
+ def gemsets
192
+ RVM.current.gemset.list
122
193
  end
123
- end
124
-
125
-
126
- # remove failing/not needed libs
127
- if OS.windows?
128
- Irbtools.libraries -= %w[coderay]
129
- end
130
-
131
- unless OS.mac?
132
- Irbtools.libraries -= %w[g]
133
- end
134
194
 
135
- if defined? Ripl
136
- Irbtools.libraries -= %w[wirb fancy_irb] # install ripl-color_result for ripl colorization ;)
195
+ def gemset(which = nil)
196
+ if which
197
+ if RVM.current.gemset.list.include? which.to_s
198
+ RVM.use! RVM.current.environment_name.gsub(/(@.*?$)|$/, "@#{ which }")
199
+ else
200
+ warn "Sorry, that gemset could not be found (see gemsets)!"
201
+ end
202
+ end
203
+ RVM.current.gemset_name
204
+ end
205
+ alias use_gemset gemset
137
206
  end
138
207
 
139
208
  # J-_-L
@@ -0,0 +1,9 @@
1
+ # require this file (instead of configure) to deactivate loading of default set of libraries
2
+
3
+ module Irbtools
4
+ @minimal = true
5
+ end
6
+
7
+ require File.expand_path( 'configure.rb', File.dirname(__FILE__) )
8
+
9
+ # J-_-L
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: irbtools
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.8.8
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jan Lelis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-28 00:00:00 Z
13
+ date: 2011-05-18 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fancy_irb
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: "9"
34
+ version: "10"
35
35
  type: :runtime
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.4.3
45
+ version: 0.4.5
46
46
  type: :runtime
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
@@ -53,7 +53,7 @@ dependencies:
53
53
  requirements:
54
54
  - - ~>
55
55
  - !ruby/object:Gem::Version
56
- version: 0.3.2
56
+ version: 0.4.0
57
57
  type: :runtime
58
58
  version_requirements: *id004
59
59
  - !ruby/object:Gem::Dependency
@@ -64,7 +64,7 @@ dependencies:
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: 0.9.7
67
+ version: 0.9.8
68
68
  type: :runtime
69
69
  version_requirements: *id005
70
70
  - !ruby/object:Gem::Dependency
@@ -97,7 +97,7 @@ dependencies:
97
97
  requirements:
98
98
  - - ">="
99
99
  - !ruby/object:Gem::Version
100
- version: 0.2.4
100
+ version: 0.2.6
101
101
  type: :runtime
102
102
  version_requirements: *id008
103
103
  - !ruby/object:Gem::Dependency
@@ -152,10 +152,32 @@ dependencies:
152
152
  requirements:
153
153
  - - ">="
154
154
  - !ruby/object:Gem::Version
155
- version: 1.2.1
155
+ version: 1.2.3
156
156
  type: :runtime
157
157
  version_requirements: *id013
158
- description: 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.
158
+ - !ruby/object:Gem::Dependency
159
+ name: rvm_loader
160
+ prerelease: false
161
+ requirement: &id014 !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 1.0.0
167
+ type: :runtime
168
+ version_requirements: *id014
169
+ - !ruby/object:Gem::Dependency
170
+ name: every_day_irb
171
+ prerelease: false
172
+ requirement: &id015 !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: 1.0.0
178
+ type: :runtime
179
+ version_requirements: *id015
180
+ description: irbtools is a meta gem that installs useful irb gems and configures your irb. Simply put a require "irbtools" in the .irbrc file in your home directory.
159
181
  email: mail@janlelis.de
160
182
  executables: []
161
183
 
@@ -166,10 +188,9 @@ extra_rdoc_files:
166
188
  - README.rdoc
167
189
  files:
168
190
  - lib/irbtools.rb
169
- - lib/irbtools/libraries.rb
170
- - lib/irbtools/general.rb
171
191
  - lib/irbtools/configure.rb
172
- - lib/irbtools/rvm.rb
192
+ - lib/irbtools/libraries.rb
193
+ - lib/irbtools/minimal.rb
173
194
  - VERSION
174
195
  - CHANGELOG
175
196
  - Rakefile
@@ -199,9 +220,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
220
  requirements: []
200
221
 
201
222
  rubyforge_project:
202
- rubygems_version: 1.7.2
223
+ rubygems_version: 1.8.1
203
224
  signing_key:
204
225
  specification_version: 3
205
- summary: irbtools is a meta gem which installs some useful irb gems and configures your irb.
226
+ summary: irbtools is a meta gem that installs useful irb gems and configures your irb.
206
227
  test_files: []
207
228
 
@@ -1,125 +0,0 @@
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 and reloading/requireing
13
- def rq(lib)
14
- require lib.to_s
15
- end
16
-
17
- # rerequire, please note: can have non-intended side effects
18
- def rerequire(lib)
19
- $".dup.grep(/#{lib}\.rb$/).each{ |path|
20
- $".delete path.to_s
21
- require path.to_s
22
- }
23
- require lib.to_s
24
- true
25
- end
26
- alias rrq rerequire
27
-
28
- # load shortcut
29
- def ld(lib)
30
- load lib.to_s + '.rb'
31
- end
32
-
33
- # returns the last lines, needed for some copy_ methods
34
- def session_history(number_of_lines = nil)
35
- if !number_of_lines
36
- if defined?(Ripl) && Ripl.instance_variable_get(:@shell) # ripl is running
37
- number_of_lines = Ripl.shell.line
38
- else
39
- number_of_lines = context.instance_variable_get(:@line_no)
40
- end
41
- end
42
- Readline::HISTORY.entries[-number_of_lines...-1]*"\n"
43
- end
44
-
45
- # restart irb
46
- def reset!
47
- # remember history...
48
- reset_irb = proc{ exec$0 }
49
- if defined?(Ripl) && Ripl.instance_variable_get(:@shell) # ripl is running
50
- Ripl.shell.write_history if Ripl.shell.respond_to? :write_history
51
- reset_irb.call
52
- else
53
- at_exit(&reset_irb)
54
- exit
55
- end
56
- end
57
-
58
- # just clear the screen
59
- def clear
60
- system 'clear'
61
- end
62
-
63
- # change ruby version (requires rvm)
64
- autoload :RVM, 'irbtools/rvm'
65
-
66
- def rubies
67
- RVM.current.list_strings
68
- end
69
-
70
- def use(which = nil) # TODO with gemsets?
71
- # show current ruby if called without options
72
- if !which
73
- return RVM.current.environment_name[/^.*@|.*$/].chomp('@')
74
- end
75
-
76
- # start ruby :)
77
- begin
78
- RVM.use! which.to_s
79
- rescue RVM::IncompatibleRubyError => err
80
- err.message =~ /requires (.*?) \(/
81
- rubies = RVM.current.list_strings
82
- if rubies.include? $1
83
- # remember history...
84
- run_irb = proc{ exec "#{ $1 } -S #{ $0 }" }
85
- if defined?(Ripl) && Ripl.instance_variable_get(:@shell) # ripl is running
86
- Ripl.shell.write_history if Ripl.shell.respond_to? :write_history
87
- run_irb.call
88
- else
89
- at_exit(&run_irb)
90
- exit
91
- end
92
- else
93
- warn "Sorry, that Ruby version could not be found (see rubies)!"
94
- end
95
- end
96
- end
97
- alias use_ruby use
98
-
99
- def gemsets
100
- RVM.current.gemset.list
101
- end
102
-
103
- def gemset(which = nil)
104
- if which
105
- if RVM.current.gemset.list.include? which.to_s
106
- RVM.use! RVM.current.environment_name.gsub /(@.*?$)|$/, "@#{ which }"
107
- else
108
- warn "Sorry, that gemset could not be found (see gemsets)!"
109
- end
110
- end
111
- RVM.current.gemset_name
112
- end
113
- alias use_gemset gemset
114
-
115
- # load debugger, inspired by rdp
116
- def dbg
117
- begin
118
- require 'ruby-debug'
119
- debugger
120
- rescue LoadError => err
121
- throw "Sorry, unable to load ruby-debug gem for debugger: #{err}"
122
- end
123
- end
124
-
125
- # J-_-L
@@ -1,8 +0,0 @@
1
- # test if installed
2
- unless rvm_path = ENV['rvm_path']
3
- raise 'Ruby Version Manager must be installed to use this command'
4
- end
5
-
6
- # load rvm ruby api
7
- $LOAD_PATH.unshift File.join(rvm_path, 'lib')
8
- require 'rvm'