Command Hooks #187

Open
h3rald opened this Issue Nov 28, 2010 · 0 comments

Projects

None yet

1 participant

@h3rald
Owner
h3rald commented Nov 28, 2010

Implementation Hints

You'd have to store Proc objects somewhere, i.e. a Glyph::HOOKS hash, maybe something like this:

  :project:
      :compile:
          :before: # proc
          :after: # proc
      :init:
      :add:
      # ...
   :global:
      :compile:
      # ...

Then you'd need something to evaluate the hooks.rb with. You could define a new class or module containing the after and before methods (and any other) or you could simply expose them at Glyph-level. At any rate, you'd have to run an instance_eval or class_eval when loading the files. The methods would be fairly simple:

 def after(command, &block)
    # Code to store block in Glyph::HOOKS[:project][command][:after]
 end

...then, all you'd have to do is to call hooks from wherever you like inside each command, for example like this:

  # compile.rb
  Glyph::HOOKS[:project][:compile][:before].call(...parameters...)
  Glyph::HOOKS[:global][:compile][:before].call(...parameters...)

This is just a possible quick-and-dirty implementation. Obviously there are much better ways to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment