Commit Graph

17 Commits

Author SHA1 Message Date
John Mair c3d27d9f31 passing extra prompt data via an OpenStruct 2012-07-13 02:53:19 +12:00
John Mair f77a2ab5ca added `before_eval` hook & tests
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
```
2012-06-24 01:48:11 +12:00
John Mair 3a4041cb24 Allow use of hash-based hooks, but show warning.
* 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.
2012-01-24 21:44:21 +13:00
John Mair 7671aa6684 Wrapped config.hooks{=} to error on old API.
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.
2012-01-24 01:41:03 +13:00
John Mair 75af6ad68d no longer yields binding_stack to whenstarted, fixed #434 2012-01-20 17:39:25 +13:00
John Mair 2827ded4a0 Pry#binding_stack respected by :when_started hook
* 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
2012-01-18 17:34:31 +13:00
Conrad Irwin f3262e3270 Make exec_hook robust to exceptions
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.
2012-01-14 00:33:36 -08:00
John Mair 437da22b4a properly cleanup after after_session test 2012-01-14 02:29:00 +13:00
John Mair e1088dbc72 after_session in ensure + tests, fixes #418
* + update gemspec
2012-01-14 02:24:13 +13:00
John Mair 2fdfbad039 added Pry::Hooks#dup/merge/merge! and tests 2012-01-12 16:56:41 +13:00
John Mair 1baf8131a0 replaced ineffective :when_started hook test with a better one. Fixed #401 2012-01-04 01:10:09 +13:00
Yorick Peterse c4f5fdda9e Pass custom options to the when_started hook.
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>
2012-01-02 20:36:39 +01:00
John Mair c800c0f04f Hook system now executes hooks in order.
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.
2011-11-23 18:55:35 +13:00
John Mair a8677c7937 renamed and refactored some tests for hooks 2011-11-19 14:54:15 +13:00
John Mair dc7e094e98 added more tests for hooks system 2011-11-17 23:20:07 +13:00
John Mair 263d621625 Hooks now have names, also improved some terminology.
Naming hooks makes them easier to reshuffle and customize.
2011-11-16 02:49:11 +13:00
John Mair c02772af19 added basic skeleton for hooks system (yet to add many hook callsites) 2011-11-13 02:37:57 +13:00