Showing posts with label irb. Show all posts
Showing posts with label irb. Show all posts

Thursday, November 10, 2011

Testing Routes in Rails

Routes in rails are really cool but they can be confusing to newbies and, as they become more complex, it can be difficult to make sure that all of your paths are still working like you expect. My intention here is not to provide a primer on routes but rather to show how easy it is to test and verify routes.

http://blog.zobie.com/2008/11/testing-routes-in-rails/

Monday, May 2, 2011

.irbrc for Win32

Create a file called anything you like (e.g. “_irbrc” or “irb.rc”) and place it anywhere you like (say C:\Documents and Settings\), and set that full path to the ENV variable IRBRC, e.g. C:\Documents and Settings\\_irbrc

Utility Belt

Utility Belt is a grab-bag of tricks, tools, techniques, trifles, and toys for IRB, including convenience methods, language patches, and useful extensions. It also includes a couple command-line widgets. Its primary inspirations were an awesome gem called Wirble and a blog post by Amy Hoy called "Secrets Of The Rails Console Ninjas".

FEATURES

  • Interactively edit IRB code in your preferred text editor
  • Read from and write to OS X clipboard
  • Post your code to Pastie with one command (OS X only)
  • Kick-ass Unix-style history buffer
  • Write command history to file or vi
  • Grep classes and methods for strings
  • Verbosity controls for regular IRB and Rails console
  • Finder shortcuts for Rails console
  • Upload shortcut for Amazon S3
  • Command-line Amazon S3 upload script
  • Command-line Google shortcut (OS X only)
  • Auto-indentation
  • _ special variable (like Unix shell var !!)
  • Extremely basic themes for Wirble syntax coloring
  • Pascal/JavaScript-style "with" statement
  • String#to_proc
  • Grammatically-correct is_an? method - no more "is_a? Array" statements
  • One-character exit command
http://utilitybelt.rubyforge.org/
http://www.rubyinside.com/irb-lets-bone-up-on-the-interactive-ruby-shell-1771.html
http://rors.org/2009/12/20/10-rails-console-tricks.html

history, separate rails/console history, syntax highliting, ...

# .irbrc - last change: 2008-01-22 (ab)

### rubygems
require 'rubygems' rescue nil

### pretty print
require 'pp'

### less verbose prompt

#IRB.conf[:PROMPT_MODE] = :SIMPLE

IRB.conf[:PROMPT][:SHORT] = {
  :PROMPT_C => "%03n:%i* ",
  :RETURN   => "%s\n",
  :PROMPT_I => "%03n:%i> ",
  :PROMPT_N => "%03n:%i ",
  :PROMPT_S => "%03n:%i%l "
}
#IRB.conf[:PROMPT_MODE] = :SHORT

### automatic indentation
IRB.conf[:AUTO_INDENT] = true

### tab completion
require 'irb/completion'
IRB.conf[:USE_READLINE] = true

### preserve history
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:EVAL_HISTORY] = 100

### syntax highlighting
require 'wirble'
Wirble.init(:skip_prompt => true, :skip_history => true)
Wirble.colorize

### irb session duration
require 'duration'
IRB_START_TIME = Time.now
at_exit { puts "\nirb session duration: #{Duration.new(Time.now - IRB_START_TIME)}" }

### aliases
alias r require

### easy YAML
def y(*data); require 'yaml'; puts YAML::dump(*data); end

### Object#tap
class Object; def tap; yield self; self; end; end

### map by method
# http://drnicwilliams.com/2006/10/04/i-love-map-by-pluralisation/
require 'map_by_method'

### method finder, e.g. "foo".what?
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32844
# http://www.nobugs.org/developer/ruby/method_finder.html
# http://redhanded.hobix.com/inspect/stickItInYourIrbrcMethodfinder.html
require 'what_methods'

### gaining temporary access to private methods
# http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html
class Class
  def publicize_methods
    saved_private_instance_methods = self.private_instance_methods
    self.class_eval { public *saved_private_instance_methods }
    yield
    self.class_eval { private *saved_private_instance_methods }
  end
end

### System-wide script/console logging
# http://toolmantim.com/article/2007/2/6/system_wide_script_console_logging
script_console_running = ENV.include?('RAILS_ENV') && IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?('console_with_helpers')
rails_running = ENV.include?('RAILS_ENV') && !(IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?('console_with_helpers'))
irb_standalone_running = !script_console_running && !rails_running

if script_console_running
  require 'logger'
  Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
end

### different history file for rails
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb_history_rails" unless irb_standalone_running
http://dotfiles.org/~localhost/.irbrc

Wednesday, November 24, 2010

Wirble: Tab-Completion and Syntax Coloring for irb

Wirble
If you haven't got tab-completion and syntax coloring in your irb, you owe it to yourself to follow these instructions right away (should work for Linux, OS X, and Cygwin users). First, install the Wirble gem:
sudo gem install wirble
Next, create or edit a file called .irbrc in your home folder (~/.irbrc), and make sure these lines are included there:
require 'rubygems'
require 'wirble'
Wirble.init
Wirble.colorize
Now play with irb and see joy similar to that in the screenshot above. Try tab-completion too. It's great!

Wednesday, August 26, 2009

Hijack: Provides an irb session to an existing ruby process

Hijack allows you to connect to any ruby process and execute code as if it were a normal irb session. Hijack does not require your target process to require any hijacking code, hijack is able to connect to any ruby process. It achieves this by using gdb to inject a payload into the process which starts up a DRb server, hijack then detaches gdb and reconnects via DRb. Please note that gdb will halt your target process while it is attached, though the injection process is very quick and your process should only be halted for a few milliseconds.

Hijack uses DRb over a unix socket file, so you need to be on the same machine as the process you want to hijack. This is by design for security reasons. You also need to run the hijack client as the same user as the remote process.

http://github.com/ileitch/hijack/tree/master

Thursday, July 2, 2009

Hirb

Hirb currently provides a mini view framework for console applications, designed to improve irb’s default output. Hirb improves console output by providing a smart pager and auto-formatting output. The smart pager detects when an output exceeds a screenful and thus only pages output as needed. Auto-formatting adds a view to an output’s class. This is helpful in separating views from content (MVC anyone?). The framework encourages reusing views by letting you package them in classes and associate them with any number of output classes. Hirb comes with tree views (see Hirb::Helpers::Tree) and table views (see Hirb::Helpers::Table). By default Hirb displays Rails’ model classes as tables. Hirb also sports a nice selection menu, Hirb::Menu.

http://tagaholic.me/hirb/doc/index.html
http://tagaholic.me/hirb/