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

Passing params into the amoeba function? #112

Open
OlegSavinov opened this issue Apr 28, 2022 · 2 comments
Open

Passing params into the amoeba function? #112

OlegSavinov opened this issue Apr 28, 2022 · 2 comments

Comments

@OlegSavinov
Copy link

OlegSavinov commented Apr 28, 2022

I need to copy objects, but with input params.

Specific example

 game = {day: 12} 

needs to become

game_copy = {day: 17}

On the inside amoeba func, there is lambda function, that allows to change all fields, but is there a way to pass "new day of the game" inside lambda or amoeba to make those changes?

I know I accomplish it with update record after copy is created, but it will not affect nested associations, that will also be copied with amoeba. The idea is to successively pass params into next associated records, to update-copy all nested records.

@dbil25
Copy link

dbil25 commented Jun 22, 2022

+1 i'd love this feature too!

to keep your example, i think it would be reasonable to have a feature like that:

class Game
  has_many :reviews
  
  amoeba do |arg|
    set :day => arg
  end
end

class Review
  amoeba do |arg|
    set :some_field => arg
   end
end

and then beeing able to call

my_game.amoeba_dup(17)
#=> results in game with day: 17 and a review with some_field: 17

@jrmhaig
Copy link
Collaborator

jrmhaig commented Jun 30, 2024

Hi. Sorry for the long delay in responding to this. I am not the original creator of this gem. Rather, I just happen to be the last person to have touched it and have managed to get admin access to it. I have a vested interested in keeping it alive as I work on a project that depends on it. In an attempt to resurrect it I am looking to work on some features and, I hope, get some activity from others.

Are you still around and interested in this feature? I have created a PR (#128) that, if I understand the problem correctly, will give the desired result although it does not work quite in the way suggested above. I would appreciate a review of the code, if you have the time.

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

3 participants