This came about because KINGSABRI wanted his pry console to only execute commands, not ruby code (lol).
I conconcated the following piece of code that achieves this, but it required a before_eval hook:
```
_pry_.hooks.add_hook(:before_eval, :kill_ruby) do |code, pry|
if !code.empty?
pry.suppress_output = true
pry.output.puts "Command #{code.strip} not found, type 'help'"
code.replace("")
end
end
```
* Shows a deprecation warning when used with a link to the new `Pry::Hooks` documentation.
* When hash-based hooks are used they create anonymous hooks for the associated event.
i.e Pry.hooks = { :before_session => proc { puts 'hi' } }, the 'name' of that hook is `nil`.
* Anonymous hooks (nil-named) are different to ordinary hooks in that they dont raise an exception when user attempts to define another of the same name, they just silently overwrite previous one. This is to
mimic the old hash-based behaviour.
* Pry::Hooks[] and Pry::Hooks[]= are defined too, and they get and set the anonymous hook for the given event, i.e hooks[:before_session] = proc { "hi" } is equivalent to: hook.add_hook(:before_session, nil,
proc { "hi" })
* Proc::Hook#[] and Pry::Hooks#[]= also display deprecation warnings.
We no longer wish to support the (undocumented!!) hash-based hooks API. When a user attempts to use this API
Pry will raise a `Pry::ObsoleteError` exception with a message telling them to use `Pry::Hooks` instead.
* If _pry_.binding_stack is set then binding_stack parameter (from :when_started) is ignored, even if it's modified.
* binding_stack parameter should eventually be removed altogther before 0.9.8 release, and people can use _pry_.binding_stack instead
The rationale for this is simple: you add hooks to enhance the core
functionality with added niceness, so you don't want a buggy hook to
break core functionality.
If you call exec_hook via an instance of Pry, it will additionally print
a warning to output whenever such an exception occurs, giving useful
information on how to debug the problem.
When calling Pry.start() the specified options are passed to the "when_started"
hook. This makes it possible for plugins (combined with commit
b270761efa) to specify their own options without
causing Pry to wet itself.
Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
Also the return value of exec_hook() is now the value of the last executed hook.
Internally, hooks now use arrays (rather than hash). Also added a get_hooks() method.
Updated tests to reflect these changes.