Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amoeba method doesn't deal with class hierarchies correctly #1

Closed
robmathews opened this issue Mar 22, 2012 · 8 comments
Closed

amoeba method doesn't deal with class hierarchies correctly #1

robmathews opened this issue Mar 22, 2012 · 8 comments

Comments

@robmathews
Copy link

If you have have:

class Post
  has_many :comments
  amoeba do enabled end
end

class EnhancedPost < Post
end

and then following code fails:

a=EnhancedPost.find(... a enhanced post with comments)
b = a.dup
b.comments.size.should == b.comments.size ## FAILS

The reason is that the Amoeba::Config in the EnhancedPost class has enabled=false (the default) b/c it is not the same instance as the Amoeba::Config in the Post base class.

I'm thinking that the amoeba block in EnhancedPost should perhaps be written this way:

class EnhancedPost < Post
  amoeba do 
      super.amoeba ## get the defaults from the base class
      ## then do anything special for EnhancedPost class
  end
end

and I'm wishing that you could include a note about the behaviour of Amoeba and inherited classes in your wonderful documentation, it took two of us quite a few hours to figure out what was happening.

Thanks!
Rob.

@robmathews
Copy link
Author

Actually, I realize you can't write it using "super.amoeba", its in the wrong context. So the problem remains - how to share parent class configuration in the child class w/o repeating yourself.

@robmathews
Copy link
Author

Actually, it's more complex than that. Consider:

class EnhancedPost < Post
  amoeba do 
      enabled # doesn't work
  end
end

but if I name the association explicitly, it works:

class EnhancedPost < Post
  amoeba do 
      enabled
      include_field :comments # this works
  end
end

@rocksolidwebdesign
Copy link
Contributor

hey, thanks for the feedback, I'll have a look at this as soon as I can. please feel free to fork it and submit a pull request with a solution if you like :)

@rocksolidwebdesign
Copy link
Contributor

hey rob... I just pushed some changes that I hope address the issues you were facing. I've updated the docs and added some tests and at a cursory glance, so far, without delving too deep - it seems to be working.

all you should have to do is add propagate to the amoeba block of Post and then EnhancedPost should duplicate the same way that Post does.

like this:

amoeba do
  enable
  propagate
end

please give it a try and let me know if it works for you. I haven't pushed up to rubygems yet, and even when I do it sometimes takes time for the new version to propagate, so please just try the gem from git HEAD and let me know how it goes.

enjoy :)

@rocksolidwebdesign
Copy link
Contributor

ok, pushed to rubygems

@robmathews
Copy link
Author

hey, that's great response. when I check it out, I'll be sure to retract my
comment on SO as well. thanx.

On Sat, Mar 24, 2012 at 8:02 PM, Vaughn Draughon <
reply@reply.github.com

wrote:

ok, pushed to rubygems


Reply to this email directly or view it on GitHub:
#1 (comment)

@rocksolidwebdesign
Copy link
Contributor

closing this issue for now since it seems to work for me

@robmathews
Copy link
Author

np

On Mon, Mar 26, 2012 at 7:24 PM, Vaughn Draughon <
reply@reply.github.com

wrote:

closing this issue for now since it seems to work for me


Reply to this email directly or view it on GitHub:
#1 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants