Permalink
Browse files

Adds before_inner_class_inheritance hook

  • Loading branch information...
1 parent 99b8d18 commit 220527a0e7d8354a49be3bc8fa8a0ce5a5438586 @hassox committed Jun 20, 2010
Showing with 21 additions and 3 deletions.
  1. +4 −0 bin/pancake
  2. +1 −1 lib/pancake/core_ext/object.rb
  3. +15 −2 lib/pancake/hooks/inheritable_inner_classes.rb
  4. +1 −0 lib/pancake/stack/stack.rb
View
4 bin/pancake
@@ -24,6 +24,10 @@ desc "list [SEARCH]", "List the available pancake tasks (--substring means .*SEA
def method_missing(meth, *args, &blk)
klass, task = Thor::Util.find_class_and_task_by_namespace(meth.to_s)
+ unless klass
+ puts "Could not find a generator for #{meth.to_s}"
+ exit(1)
+ end
args.unshift(task) if task
klass.start(args, :shell => self.shell)
end
View
2 lib/pancake/core_ext/object.rb
@@ -19,4 +19,4 @@ def instance_exec(*args, &block)
ret
end
end
-end
+end
View
17 lib/pancake/hooks/inheritable_inner_classes.rb
@@ -3,8 +3,9 @@ module Hooks
module InheritableInnerClasses
def self.extended(base)
base.class_eval do
- extlib_inheritable_reader :_inhertiable_inner_classes
- @_inhertiable_inner_classes = []
+ extlib_inheritable_reader :_inhertiable_inner_classes, :_before_inner_class_inheritance
+ @_inhertiable_inner_classes = []
+ @_before_inner_class_inheritance = []
end
end # extended
@@ -40,6 +41,16 @@ def inheritable_inner_classes(*classes)
_inhertiable_inner_classes
end
+ # Runs any hooks before the inheritance of any inner classes
+ #
+ # @api public
+ # @since 0.3.0
+ # @author Daniel Neighman
+ def before_inner_class_inheritance(&blk)
+ _before_inner_class_inheritance << blk if blk
+ _before_inner_class_inheritance
+ end
+
# The inherited hook that sets up inherited inner classes. Remember if you overwrite this method, you should
# call super!
#
@@ -49,11 +60,13 @@ def inheritable_inner_classes(*classes)
def inherited(base)
super
class_defs = inheritable_inner_classes.map do |klass|
+ _before_inner_class_inheritance.each{|blk| blk.call(base.superclass) }
"class #{klass} < superclass::#{klass}; end\n"
end
base.class_eval(class_defs.join)
end
+
end # InheritableInnerClasses
end # Hooks
end # Pancake
View
1 lib/pancake/stack/stack.rb
@@ -23,6 +23,7 @@ class Stack
#Iterates the list of roots in the stack, and initializes the app found their
def self.initialize_stack(opts = {})
+ return if @initialized
raise "Stack root not set" if roots.empty?
master = opts.delete(:master)
set_as_master! if master

0 comments on commit 220527a

Please sign in to comment.