clowne-rb / clowne

A flexible gem for cloning models
https://clowne.evilmartians.io
MIT License
316 stars 18 forks source link

Add inline configuration support #8

Closed palkan closed 6 years ago

palkan commented 6 years ago

It turned out to be very useful to have the following feature:

cloned = UserCloner.call(User.last) do
  exclude_association :profile

  finalize do |source, record|
    record.email = "clone_of_#{source.email}"
  end
end
sponomarev commented 6 years ago

As far as I understand, incline configuration extends the current one, is there any way to redefine the existent or just reset it, for example, finalize block?

palkan commented 6 years ago

@sponomarev To reset you can use a plain cloner class, i.e.:

cloned = Clowne::Cloner.call(user) do
  # ...
end

Cloners are not bound to specific models.

sponomarev commented 6 years ago

@palkan Perfect approach which deserves to be mentioned in README!