class Stall::Addresses::CopySourceToTarget
Public Instance Methods
copy()
click to toggle source
# File lib/stall/addresses/copy_source_to_target.rb, line 10 def copy copy_address(:shipping) copy_address(:billing) end
copy!()
click to toggle source
# File lib/stall/addresses/copy_source_to_target.rb, line 5 def copy! copy target.save! end
Private Instance Methods
copy_address(type)
click to toggle source
Update or create target address with source attributes
# File lib/stall/addresses/copy_source_to_target.rb, line 19 def copy_address(type) source.with_actual_address_associations do target.with_actual_address_associations do address = if target.send(:"#{ type }_address?") target.send(:"#{ type }_address") else target.send(:"build_#{ type }_address") end if source.send(:"#{ type }_address?") attributes = duplicate_attributes(source.send(:"#{ type }_address")) address.assign_attributes(attributes) else address.try(:mark_for_destruction) end end end end