#!/usr/bin/env ruby # The command line Restfully client require 'restfully' require 'optparse' require 'logger' require 'pp' require 'ripl' require 'ripl/multi_line' # Behaviour of pp in IRB is different on ruby1.9: # * pp(object) returns object#inspect. # * we prefer the behaviour of ruby1.8 where pp returns nil. alias :old_pp :pp def pp(*args) old_pp(*args); nil end logger = Logger.new(STDERR) logger.level = Logger::WARN OPTIONS = {"logger" => logger, "shell" => false} Ripl.config[:play_quiet] = true Ripl.config[:play_input] = false option_parser = OptionParser.new do |opts| opts.banner = < :ruby } module Ripl::Exit def before_loop; super; exit; end end Ripl::Shell.include Ripl::Exit end Ripl.config[:play] = ARGV[0].dup if ARGV[0] end module Restfully class Session alias :old_initialize :initialize # Overwrite Restfully::Session.new calls that might occur in replayed # scripts, so that they preferably take the configuration given with the # restfully command-line tool. def initialize(options = {}, &block) old_opts = Configuration.new(options).expand new_opts = Configuration.new(OPTIONS).expand old_initialize(old_opts.merge(new_opts).to_hash, &block) end end end # Ensure to close the log file, if any, when exiting. at_exit{ @log_file && @log_file.close } ARGV.clear Ripl.start :binding => @session.instance_eval{ binding }