Sha256: 8d7a608f4db496179d345ba8d7251d138c105807f8750cdf6577a7e828f31ba4

Contents?: true

Size: 764 Bytes

Versions: 11

Compression:

Stored size: 764 Bytes

Contents

module DiscoApp::Concerns::Synchronises
  extend ActiveSupport::Concern

  class_methods do

    def should_synchronise?(shop, data)
      true
    end

    def synchronise(shop, data)
      data = data.with_indifferent_access

      return unless should_synchronise?(shop, data)

      instance = self.find_or_create_by!(id: data[:id]) do |instance|
        instance.shop = shop
        instance.data = data
      end

      instance.update(data: data)

      instance
    end

    def should_synchronise_deletion?(shop, data)
      true
    end

    def synchronise_deletion(shop, data)
      data = data.with_indifferent_access

      return unless should_synchronise_deletion?(shop, data)

      self.destroy_all(shop: shop, id: data[:id])
    end

  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
disco_app-0.8.6 app/models/disco_app/concerns/synchronises.rb
disco_app-0.8.7 app/models/disco_app/concerns/synchronises.rb
disco_app-0.8.8 app/models/disco_app/concerns/synchronises.rb
disco_app-0.8.9 app/models/disco_app/concerns/synchronises.rb
disco_app-0.9.0 app/models/disco_app/concerns/synchronises.rb
disco_app-0.9.1 app/models/disco_app/concerns/synchronises.rb
disco_app-0.9.2 app/models/disco_app/concerns/synchronises.rb
disco_app-0.9.3 app/models/disco_app/concerns/synchronises.rb
disco_app-0.9.4 app/models/disco_app/concerns/synchronises.rb
disco_app-0.9.5 app/models/disco_app/concerns/synchronises.rb
disco_app-0.9.6 app/models/disco_app/concerns/synchronises.rb