Sha256: d8fa6f49d56256005ec5f4ffe96cb5ffb23580cac07361a725f5376c5adcc540

Contents?: true

Size: 825 Bytes

Versions: 15

Compression:

Stored size: 825 Bytes

Contents

# frozen_string_literal: true

module SolidusBactracs
  module Api
    class ThresholdVerifier
      class << self
        def call(shipment)
          return false unless shipment.order.completed?

          !!(shipment_requires_creation?(shipment) || shipment_requires_update?(shipment))
        end

        private

        def shipment_requires_creation?(shipment)
          shipment.bactracs_synced_at.nil? &&
            Time.zone.now - shipment.order.updated_at < SolidusBactracs.config.api_sync_threshold
        end

        def shipment_requires_update?(shipment)
          shipment.bactracs_synced_at &&
            shipment.bactracs_synced_at < shipment.order.updated_at &&
            Time.zone.now - shipment.order.updated_at < SolidusBactracs.config.api_sync_threshold
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
solidus_bactracs-4.0.1 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-4.0.0 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.5.2 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.5.1 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.5.0 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.4.0 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.3.2 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.3.1 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.3.0 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.2.2 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.2.1 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.2.0 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.1.2 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.1.1 lib/solidus_bactracs/api/threshold_verifier.rb
solidus_bactracs-3.1.0 lib/solidus_bactracs/api/threshold_verifier.rb