Sha256: 12df1ffc47d7e6fef8759f63141e4f908de504ecee3928ba2beda60a1db04499

Contents?: true

Size: 838 Bytes

Versions: 2

Compression:

Stored size: 838 Bytes

Contents

module Workarea
  decorate Shipping::Address, with: :shipping_estimation do
    decorated do
      field :used_for_shipping_estimation, type: Boolean, default: false

      before_validation :set_estimate_data
      after_validation :unset_estimate_data
    end

    def set_estimate_data
      return unless used_for_shipping_estimation?

      Workarea.config
              .shipping_estimation_placeholder_address
              .each do |field, value|
                send("#{field}=", value) if send(field).blank?
              end
    end

    def unset_estimate_data
      return unless used_for_shipping_estimation?

      Workarea.config
              .shipping_estimation_placeholder_address
              .each do |field, value|
                send("#{field}=", nil) if send(field) == value
              end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-shipping_estimation-1.1.3 app/models/workarea/shipping/address.decorator
workarea-shipping_estimation-1.1.2 app/models/workarea/shipping/address.decorator