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) * User can whitelist objects whose inspect output should appear in prompt (#885)
* See `Pry.config.prompt_safe_objects` * See `Pry.config.prompt_safe_objects`
* `whereami` is now aliased to `@` * `whereami` is now aliased to `@`
* improve configuration(Pry.config) to lazy-load default configuration values. (#1096)
#### Bug fixes, etc. #### Bug fixes, etc.
* `binding.pry` inside `.pryrc` file now works, with some limitations (@richo / #1118)
* Add support for BasicObjects to `ls` (#984) * Add support for BasicObjects to `ls` (#984)
* Allow `ls -c <anything>` (#891) * Allow `ls -c <anything>` (#891)
* Fix indentation not working if the `mathn` stdlib was loaded (#872) * 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. * Fix bug in `edit` regarding recognition of file names without suffix.
#### Dev-facing changes #### 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`) * `rake pry` now accepts switches prefixed with `_` (e.g., `rake pry _v`)
* Pagers now act like `IO`s and accept streaming output * Pagers now act like `IO`s and accept streaming output
* See `Pager.page` and `Pager.with_pager` * See `Pager.page` and `Pager.with_pager`

View File

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

View File

@ -79,14 +79,24 @@ module Pry::Config::Behavior
def inherited_by(other) def inherited_by(other)
if @inherited_by 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 else
@inherited_by = other @inherited_by = other
end end
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 def to_hash
@writes @writes.dup
end end
alias_method :to_h, :to_hash alias_method :to_h, :to_hash

View File

@ -34,9 +34,12 @@ class Pry
@main ||= TOPLEVEL_BINDING.eval "self" @main ||= TOPLEVEL_BINDING.eval "self"
end 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 def self.current
Thread.current[:__pry__] ||= {} Thread.current[:__pry__] ||= Pry::Config.from_hash({}, nil)
end end
# Load the given file in the context of `Pry.toplevel_binding` # Load the given file in the context of `Pry.toplevel_binding`
@ -51,9 +54,11 @@ class Pry
# This method can also be used to reload the files if they have changed. # This method can also be used to reload the files if they have changed.
def self.load_rc_files def self.load_rc_files
rc_files_to_load.each do |file| rc_files_to_load.each do |file|
critical_section do
load_file_at_toplevel(file) load_file_at_toplevel(file)
end end
end end
end
# Load the local RC file (./.pryrc) # Load the local RC file (./.pryrc)
def self.rc_files_to_load def self.rc_files_to_load

View File

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

View File

@ -180,9 +180,6 @@ class Pry
end end
if defined?(Readline) and input == Readline 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 input_readline(current_prompt, false) # false since we'll add it manually
elsif defined? Coolline and input.is_a? Coolline elsif defined? Coolline and input.is_a? Coolline
input_readline(current_prompt) input_readline(current_prompt)

View File

@ -37,6 +37,43 @@ describe Pry::Config do
end end
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 describe "#forget" do
it "forgets a local key" do it "forgets a local key" do
local = Pry::Config.new Pry::Config.from_hash(foo: 1) local = Pry::Config.new Pry::Config.from_hash(foo: 1)
@ -53,17 +90,23 @@ describe Pry::Config do
local.foo = "21" local.foo = "21"
local.to_hash.should == { "foo" => "21" } local.to_hash.should == { "foo" => "21" }
end 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 end
describe "#merge!" do describe "#merge!" do
it "can merge a Hash-like object" 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.merge! Pry::Config.from_hash(foo: 21)
local.foo.should == 21 local.foo.should == 21
end end
it "can merge a Hash" do it "can merge a Hash" do
local = Pry::Config.new local = Pry::Config.new(nil)
local.merge!(foo: 21) local.merge!(foo: 21)
local.foo.should == 21 local.foo.should == 21
end end