Skip to content

Commit

Permalink
Merge pull request #1504 from strcmp/lazyhistory
Browse files Browse the repository at this point in the history
lazy load the config defaults for "history" and "gist"
  • Loading branch information
strcmp committed Jan 1, 2016
2 parents c584d17 + 469d48c commit 92542e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 13 additions & 20 deletions lib/pry/config/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,29 @@ 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 {
""
}
})

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
Expand Down

0 comments on commit 92542e0

Please sign in to comment.