bin/restfully in restfully-1.0.0.rc1 vs bin/restfully in restfully-1.0.0.rc2
- old
+ new
@@ -5,10 +5,11 @@
require 'optparse'
require 'logger'
require 'pp'
require 'ripl'
require 'ripl/multi_line'
+require 'ripl/short_errors'
# 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
@@ -65,11 +66,10 @@
opts.on("--no-cache", "Disable client-side caching") do |v|
OPTIONS["cache"] = false
end
opts.on("--color", "Color output") do |v|
require 'ripl/color_streams'
- require 'ripl/color_result'
end
opts.on("--record [SESSION_FILE]", "Record interactive session into SESSION_FILE (default=#{Restfully::DEFAULT_TAPE}), to be replayed later. This option is ignored if FILE is given.") do |v|
OPTIONS["record"] = v || Restfully::DEFAULT_TAPE
end
opts.on("-v", "--verbose", "Run verbosely") do |v|
@@ -102,24 +102,22 @@
puts Restfully::VERSION
exit
end
end.parse!
-# Declare original Restfully::Session
-@session = Restfully::Session.new(OPTIONS)
-
if $stdin.tty? && !ARGV[0]
# Interactive session
+ OPTIONS["shell"] = true
puts "Restfully/#{Restfully::VERSION} - The root resource is available in the 'root' variable."
if OPTIONS["record"]
# Recording requested
require 'ripl/record'
Ripl.config[:play] = OPTIONS["record"]
end
else
# Replayed session
- @session.logger.warn "--record option valid only with interactive session. Ignoring." if OPTIONS["record"]
+ logger.warn "--record option valid only with interactive session. Ignoring." if OPTIONS["record"]
require 'ripl/play'
module Ripl::Play
# Overwrite #get_input so that it does not display the input if not
# required.
@@ -151,24 +149,28 @@
end
Ripl.config[:play] = ARGV[0].dup if ARGV[0]
end
+# Declare original Restfully::Session
+SESSION = Restfully::Session.new(OPTIONS)
+
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)
+ options[:overridden] = true
old_opts = Configuration.new(options).expand
- new_opts = Configuration.new(OPTIONS).expand
- old_initialize(old_opts.merge(new_opts).to_hash, &block)
+ new_opts = old_opts.merge(SESSION.config)
+ old_initialize(new_opts, &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 }
+Ripl.start :binding => SESSION.sandbox.instance_eval{ binding }