Skip to content

Commit

Permalink
Adds before_inner_class_inheritance hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neighman committed Jun 20, 2010
1 parent 99b8d18 commit 220527a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions bin/pancake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pancake/core_ext/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def instance_exec(*args, &block)
ret
end
end
end
end
17 changes: 15 additions & 2 deletions lib/pancake/hooks/inheritable_inner_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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!
#
Expand All @@ -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
1 change: 1 addition & 0 deletions lib/pancake/stack/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 220527a

Please sign in to comment.