Sha256: d33469fad6a41e4753a7446fd6467343f388ffc73416e0459c0ff9f11b4c609d
Contents?: true
Size: 726 Bytes
Versions: 1
Compression:
Stored size: 726 Bytes
Contents
# Finalization To apply custom transformations to the cloned record, you can use the `finalize` declaration: ```ruby class UserCloner < Clowne::Cloner finalize do |_source, record, _params| record.name = "This is copy!" end trait :change_email do finalize do |_source, record, params| record.email = params[:email] end end end cloned = UserCloner.call(user).to_record cloned.name # => 'This is copy!' cloned.email == "clone@example.com" # => false cloned2 = UserCloner.call(user, traits: :change_email).to_record cloned2.name # => 'This is copy!' cloned2.email # => 'clone@example.com' ``` Finalization blocks are called at the end of the [cloning process](getting_started?id=execution-order).
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
clowne-1.2.0 | docs/finalize.md |