From 469d48c7be432334d3af6d053479fb8b9c598dbb Mon Sep 17 00:00:00 2001 From: strcmp <28xdb6+fvutuvy4f@grr.la> Date: Fri, 1 Jan 2016 17:20:50 +0000 Subject: [PATCH] lazy load the config defaults for "history" and "gist" --- CHANGELOG.md | 1 + lib/pry/config/default.rb | 33 +++++++++++++-------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da2829d0..b8c65b5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ * `Pry::CLI.parse_options` does not start Pry anymore ([#1393](https://github.com/pry/pry/pull/1393)) * The gem uses CPU-less platforms for Windows now ([#1410](https://github.com/pry/pry/pull/1410)) * Add `Pry::Config::Lazy` to make it easier to reimplement `Pry::Config::Default` without knowing its implementation [#1503](https://github.com/pry/pry/pull/1503/) +* Lazy load the config defaults for `Pry.config.history` and `Pry.config.gist`. ### 0.10.1 diff --git a/lib/pry/config/default.rb b/lib/pry/config/default.rb index 8c7a1dfa..bc5da406 100644 --- a/lib/pry/config/default.rb +++ b/lib/pry/config/default.rb @@ -112,6 +112,19 @@ class Pry::Config::Default require "pry/input_completer" Pry::InputCompleter }, + gist: proc { + Pry::Config.from_hash({inspecter: proc(&:pretty_inspect)}, nil) + }, + history: proc { + Pry::Config.from_hash({should_save: true, should_load: true}, nil).tap do |history| + history.file = File.expand_path("~/.pry_history") rescue nil + if history.file.nil? + self.should_load_rc = false + history.should_save = false + history.should_load = false + end + end + }, exec_string: proc { "" } @@ -119,29 +132,9 @@ class Pry::Config::Default def initialize super(nil) - configure_gist - configure_history end private - # TODO: - # all of this configure_* stuff is a relic of old code. - # we should try move this code to being command-local. - def configure_gist - self["gist"] = Pry::Config.from_hash(inspecter: proc(&:pretty_inspect)) - end - - def configure_history - self["history"] = Pry::Config.from_hash "should_save" => true, - "should_load" => true - history.file = File.expand_path("~/.pry_history") rescue nil - if history.file.nil? - self.should_load_rc = false - history.should_save = false - history.should_load = false - end - end - def lazy_readline require 'readline' Readline