module Irbtools
require this file (instead of configure) to deactivate loading of default set of libraries
Constants
- VERSION
Attributes
a hash of arrays of libraries that get loaded keys determine if lib is required, required on sub-session or autoloaded
set this to true before loading this file to deactivate loading of default libraries
shell name (usually irb), retrieved from $0
message to display when starting. Set to nil to disable
Public Class Methods
Source
# File lib/irbtools/implementation.rb, line 137 def add_command_aliases IRB.conf[:COMMAND_ALIASES] = (IRB.conf[:COMMAND_ALIASES] || {}).merge({ :ri => :show_doc, :co => :chws, :'$' => :sys, :'+' => :shadow, }) end
Source
# File lib/irbtools/implementation.rb, line 24 def add_library(lib, options = {}, &block) lib = lib.to_s if constant = options[:autoload] lib_path = File.split( lib ); lib_path.delete('.') gem_name = lib_path[0] # assume that first dir in load dir is the gem name if constant.is_a?(Array) constant.each{ |single_constant| @libraries[:autoload] << [single_constant, lib, gem_name] } else @libraries[:autoload] << [constant, lib, gem_name] end elsif options[:after_rc] @libraries[:after_rc] << lib elsif which = options[:thread] @libraries[:thread][which] ||= [] @libraries[:thread][which] << lib elsif options[:late] @libraries[:late] << lib elsif which = options[:late_thread] @libraries[:late_thread][which] ||= [] @libraries[:late_thread][which] << lib else @libraries[:start] << lib end add_library_callback(lib, &block) if block_given? end
add a library. the block gets executed, when the library was loaded. if the second param is true, it’s hooked in into IRB.conf instead of the start.
Source
# File lib/irbtools/implementation.rb, line 55 def add_library_callback(lib, &block) lib = lib.to_s @lib_hooks[lib] << block end
add a callback that gets (usually) executed after loading the library
Source
# File lib/irbtools/implementation.rb, line 104 def configure_irb! if defined?(IRB) IRB.conf[:AUTO_INDENT] = true # simple auto indent IRB.conf[:EVAL_HISTORY] = 42424242424242424242 # creates the special __ variable IRB.conf[:SAVE_HISTORY] = 2000 # how many lines will go to ~/.irb_history set_propmt load_commands add_command_aliases rename_ls_to_ils end end
Source
# File lib/irbtools/implementation.rb, line 83 def library_loaded(lib) @lib_hooks[lib.to_s].each{ |hook| hook.call } end
te be triggered when a library has loaded
Source
# File lib/irbtools/implementation.rb, line 129 def load_commands IRB::Command.register(:code, Irbtools::Command::Code) IRB::Command.register(:howtocall, Irbtools::Command::Howtocall) IRB::Command.register(:look, Irbtools::Command::Look) IRB::Command.register(:shadow, Irbtools::Command::Shadow) IRB::Command.register(:sys, Irbtools::Command::Sys) end
Source
# File lib/irbtools/implementation.rb, line 88 def load_libraries(libs) remember_verbose_and_debug = $VERBOSE, $DEBUG $VERBOSE = $DEBUG = false libs.each{ |lib| begin require lib.to_s library_loaded(lib) rescue Exception => err warn "Error while loading a library into IRB:\n\n### #{err.class}\n" + err.message + "\n\n### STACKTRACE\n " + err.backtrace*"\n " + "\n\n\n" end } $VERBOSE, $DEBUG = remember_verbose_and_debug end
actually load libraries
Source
# File lib/irbtools/implementation.rb, line 69 def remove_library(lib) lib = lib.to_s @libraries[:start].delete lib @libraries[:sub_session].delete lib @libraries[:autoload].reject!{|_,e,| e == lib } @libraries[:thread].each{ |_,libs| libs.delete lib } @libraries[:late].delete lib @libraries[:late_thread].each{ |_,libs| libs.delete lib } @lib_hooks.delete lib end
don’t load a specific library
Source
# File lib/irbtools/implementation.rb, line 147 def rename_ls_to_ils if aliases = IRB::ExtendCommandBundle.instance_variable_get(:@ALIASES) if irb_ls = aliases.find{|a,*| a == :ls} irb_ls[0] = :ils end end end
prevent clash between IRB’s ls and FileUtil’s ls
Source
# File lib/irbtools/implementation.rb, line 62 def replace_library_callback(lib, &block) lib = lib.to_s @lib_hooks[lib].clear @lib_hooks[lib] << block end
replace all callbacks with the new one given in the block a callback that gets (usually) executed after loading the library
Source
# File lib/irbtools/implementation.rb, line 116 def set_propmt (IRB.conf[:PROMPT] ||= {} ).merge!( {:IRBTOOLS => { :PROMPT_I => ">> ", # normal :PROMPT_N => "| ", # indenting :PROMPT_C => " > ", # continuing a statement :PROMPT_S => "%l> ", # continuing a string :RETURN => "=> %s \n", :AUTO_INDENT => true, }}) IRB.conf[:PROMPT_MODE] = :IRBTOOLS end
Source
# File lib/irbtools/implementation.rb, line 156 def start require 'irbtools' end
loads all the stuff