Merge branch 'master' into lazy-readline

Conflicts:
	lib/pry/repl.rb
This commit is contained in:
Ryan Fitzgerald 2014-02-02 15:44:30 -08:00
commit b9b87171f9
8 changed files with 75 additions and 15 deletions

View File

@ -1 +0,0 @@
2.1

View File

@ -21,8 +21,10 @@
* User can whitelist objects whose inspect output should appear in prompt (#885)
* See `Pry.config.prompt_safe_objects`
* `whereami` is now aliased to `@`
* improve configuration(Pry.config) to lazy-load default configuration values. (#1096)
#### Bug fixes, etc.
* `binding.pry` inside `.pryrc` file now works, with some limitations (@richo / #1118)
* Add support for BasicObjects to `ls` (#984)
* Allow `ls -c <anything>` (#891)
* Fix indentation not working if the `mathn` stdlib was loaded (#872)
@ -43,6 +45,10 @@
* Fix bug in `edit` regarding recognition of file names without suffix.
#### Dev-facing changes
* through changes to configuration, all commands should reference configuration values
via `_pry_.config` and not `Pry.config`. (#1096)
* improve configuration(Pry::Config) for easier support of concurrent environments
through a 'pry-local' config who, at times, acts as a 'pry-local store'. (#1096)
* `rake pry` now accepts switches prefixed with `_` (e.g., `rake pry _v`)
* Pagers now act like `IO`s and accept streaming output
* See `Pager.page` and `Pager.with_pager`

View File

@ -1,7 +1,7 @@
class Pry::Config
require 'pry/config/behavior'
require 'pry/config/default'
require 'pry/config/convenience'
require_relative 'config/behavior'
require_relative 'config/default'
require_relative 'config/convenience'
include Pry::Config::Behavior
def self.shortcuts

View File

@ -79,14 +79,24 @@ module Pry::Config::Behavior
def inherited_by(other)
if @inherited_by
raise RuntimeError, "instance of Pry::Config should be inherited by only one instance"
raise RuntimeError, "instance of '#{self.class}' cannot reassign its child."
else
@inherited_by = other
end
end
def ==(other)
return false unless other.respond_to?(:to_hash)
to_hash == other.to_hash
end
alias_method :eql?, :==
def keys
@writes.keys
end
def to_hash
@writes
@writes.dup
end
alias_method :to_h, :to_hash

View File

@ -34,9 +34,12 @@ class Pry
@main ||= TOPLEVEL_BINDING.eval "self"
end
# @return [Hash] Pry's `Thread.current` hash
#
# @return [Pry::Config]
# Returns a value store for an instance of Pry running on the current thread.
#
def self.current
Thread.current[:__pry__] ||= {}
Thread.current[:__pry__] ||= Pry::Config.from_hash({}, nil)
end
# Load the given file in the context of `Pry.toplevel_binding`
@ -51,7 +54,9 @@ class Pry
# This method can also be used to reload the files if they have changed.
def self.load_rc_files
rc_files_to_load.each do |file|
load_file_at_toplevel(file)
critical_section do
load_file_at_toplevel(file)
end
end
end

View File

@ -66,7 +66,7 @@ class Pry
@indent = Pry::Indent.new
@command_state = {}
@eval_string = ""
@backtrace = options[:backtrace] || caller
@backtrace = options.delete(:backtrace) || caller
@config = Pry::Config.new
config.merge!(options)
push_prompt(config.prompt)

View File

@ -180,9 +180,6 @@ class Pry
end
if defined?(Readline) and input == Readline
if !$stdout.tty? && $stdin.tty? && !Pry::Helpers::BaseHelpers.windows?
input.output = File.open('/dev/tty', 'w')
end
input_readline(current_prompt, false) # false since we'll add it manually
elsif defined? Coolline and input.is_a? Coolline
input_readline(current_prompt)

View File

@ -37,6 +37,43 @@ describe Pry::Config do
end
end
describe ".from_hash" do
it "returns an object without a default when given 1 argument" do
local = Pry::Config.from_hash({})
local.instance_variable_get(:@default).should == nil
end
it "returns an object with a default when given 2 arguments" do
default = Pry::Config.new(nil)
local = Pry::Config.from_hash({}, default)
local.instance_variable_get(:@default).should == default
end
end
describe "#keys" do
it "returns an array of local keys" do
root = Pry::Config.from_hash({zoo: "boo"}, nil)
local = Pry::Config.from_hash({foo: "bar"}, root)
local.keys.should == ["foo"]
end
end
describe "#==" do
it "compares equality through the underlying lookup table" do
local1 = Pry::Config.new(nil)
local2 = Pry::Config.new(nil)
local1.foo = "hi"
local2.foo = "hi"
local1.should == local2
end
it "compares equality against an object who does not implement #to_hash" do
local1 = Pry::Config.new(nil)
local1.should.not == Object.new
end
end
describe "#forget" do
it "forgets a local key" do
local = Pry::Config.new Pry::Config.from_hash(foo: 1)
@ -53,17 +90,23 @@ describe Pry::Config do
local.foo = "21"
local.to_hash.should == { "foo" => "21" }
end
it "returns a duplicate of the lookup table" do
local = Pry::Config.new(nil)
local.to_hash.merge!("foo" => 42)
local.foo.should.not == 42
end
end
describe "#merge!" do
it "can merge a Hash-like object" do
local = Pry::Config.new
local = Pry::Config.new(nil)
local.merge! Pry::Config.from_hash(foo: 21)
local.foo.should == 21
end
it "can merge a Hash" do
local = Pry::Config.new
local = Pry::Config.new(nil)
local.merge!(foo: 21)
local.foo.should == 21
end