Skip to content

Commit

Permalink
fixed syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Aug 2, 2011
1 parent afc4efa commit a0be4bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Gemfile
@@ -1,8 +1,8 @@
source :gemcutter

gem 'mongoid', '>= 2.0.2'
gem 'mongoid', '>= 2.0.1'
gem "mongoid_adjust", '>= 0.1.1'
gem 'bson_ext', '>= 1.0.1'
gem 'bson_ext', '>= 1.2'

group :test do
gem 'rspec', '>= 2.4.0'
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.3.1
0.3.2
32 changes: 16 additions & 16 deletions lib/mongoid/embedded_helper.rb
Expand Up @@ -2,51 +2,51 @@

module Mongoid
module EmbeddedHelper
def self.included(model)
model.class_eval do
def self.included(model)
model.class_eval do
alias_method :old_parentize, :parentize
def parentize(document)
old_parentize document
send(:after_parentize) if respond_to?(:after_parentize)
# run_callbacks(:after_parentize)
end
# run_callbacks(:after_parentize)
end
end
end

def in_collection stack = []
stack.extend(ArrayExt) if stack.empty?
if embedded?
if embedded?
stack.add_collection_name self
if _parent.respond_to?(:in_collection)
_parent.in_collection(stack)
else
iterate_collection_stack stack, _parent
end
else
return self.class if stack.empty?
else
return self.class if stack.empty?
iterate_collection_stack stack
end
end
private

private

def iterate_collection_stack stack, subject = nil
collection = subject || self
stack = stack.reverse
stack.each do |entry|
sub_collection = collection.send entry[:collection_name]
index = sub_collection.to_a.index(entry[:object]) if entry != stack.last
sub_collection = collection.send entry[:collection_name]
index = sub_collection.to_a.index(entry[:object]) if entry != stack.last
collection = sub_collection[index] if index
collection = sub_collection if !index
end
collection
end

module ArrayExt
def add_collection_name obj
self << {:collection_name => obj.collection_name, :object => obj}
end
end
end
end
end
end

Expand Down

0 comments on commit a0be4bf

Please sign in to comment.