Permalink
Browse files

Initial initializer impl

  • Loading branch information...
1 parent 805369c commit 99b8248f6e83b87fc7f09e43a11c68aebcb2712e Yehuda Katz + Carl Lerche committed Jun 18, 2009
Showing with 6 additions and 11 deletions.
  1. +6 −11 railties/test/new_initializer_test.rb
@@ -11,20 +11,15 @@ def initialize
end
def add(name, options = {}, &block)
- if other = options[:before] || options[:after] and !@names[other]
- raise Error, "The #{other.inspect} initializer does not exist"
+ # If :before or :after is specified, set the index to the right spot
+ if other = options[:before] || options[:after]
+ raise Error, "The #{other.inspect} initializer does not exist" unless @names[other]
+ index = @initializers.index(@names[other])
+ index += 1 if options[:after]
end
Class.new(Initializer, &block).new.tap do |initializer|
- index = if options[:before]
- @initializers.index(@names[other])
- elsif options[:after]
- @initializers.index(@names[other]) + 1
- else
- -1
- end
-
- @initializers.insert(index, initializer)
+ @initializers.insert(index || -1, initializer)
@names[name] = initializer
end
end

0 comments on commit 99b8248

Please sign in to comment.