Sha256: e151ebca13fcc212fea47b9e8bf324d427e49a8ac42cdabf820e98bc855564ad

Contents?: true

Size: 940 Bytes

Versions: 11

Compression:

Stored size: 940 Bytes

Contents

# frozen_string_literal: true

module TableSync::Publishing::Data
  class Objects
    attr_reader :objects, :event

    def initialize(objects:, event:)
      @objects = objects
      @event   = TableSync::Event.new(event)
    end

    def construct
      {
        model: model,
        attributes: attributes_for_sync,
        version: version,
        event: event.resolve,
        metadata: event.metadata,
      }
    end

    private

    def model
      if object_class.respond_to?(:table_sync_model_name)
        object_class.table_sync_model_name
      else
        object_class.name
      end
    end

    def version
      Time.current.to_f
    end

    def object_class
      objects.first.object_class
    end

    def attributes_for_sync
      objects.map do |object|
        if event.destroy?
          object.attributes_for_destroy
        else
          object.attributes_for_update
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
table_sync-6.5.1 lib/table_sync/publishing/data/objects.rb
table_sync-6.5.0 lib/table_sync/publishing/data/objects.rb
table_sync-6.4.2 lib/table_sync/publishing/data/objects.rb
table_sync-6.4.1 lib/table_sync/publishing/data/objects.rb
table_sync-6.4.0 lib/table_sync/publishing/data/objects.rb
table_sync-6.3.0 lib/table_sync/publishing/data/objects.rb
table_sync-6.1.0 lib/table_sync/publishing/data/objects.rb
table_sync-6.0.4 lib/table_sync/publishing/data/objects.rb
table_sync-6.0.3 lib/table_sync/publishing/data/objects.rb
table_sync-6.0.2 lib/table_sync/publishing/data/objects.rb
table_sync-6.0 lib/table_sync/publishing/data/objects.rb