Sha256: aa2b453b882f4e13e3ff11508bebbb8ab24c7496b8c8f7017c43721213f6f057

Contents?: true

Size: 930 Bytes

Versions: 11

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module TableSync::Publishing::Helpers
  class Objects
    attr_reader :object_class, :original_attributes, :event

    def initialize(object_class:, original_attributes:, event:)
      @event               = TableSync::Event.new(event)
      @object_class        = object_class.constantize
      @original_attributes = Array.wrap(original_attributes)
    end

    def construct_list
      if event.destroy?
        init_objects
      else
        without_empty_objects(find_objects)
      end
    end

    private

    def without_empty_objects(objects)
      objects.reject(&:empty?)
    end

    def init_objects
      original_attributes.map do |attrs|
        TableSync.publishing_adapter.new(object_class, attrs).init
      end
    end

    def find_objects
      original_attributes.map do |attrs|
        TableSync.publishing_adapter.new(object_class, attrs).find
      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/helpers/objects.rb
table_sync-6.5.0 lib/table_sync/publishing/helpers/objects.rb
table_sync-6.4.2 lib/table_sync/publishing/helpers/objects.rb
table_sync-6.4.1 lib/table_sync/publishing/helpers/objects.rb
table_sync-6.4.0 lib/table_sync/publishing/helpers/objects.rb
table_sync-6.3.0 lib/table_sync/publishing/helpers/objects.rb
table_sync-6.1.0 lib/table_sync/publishing/helpers/objects.rb
table_sync-6.0.4 lib/table_sync/publishing/helpers/objects.rb
table_sync-6.0.3 lib/table_sync/publishing/helpers/objects.rb
table_sync-6.0.2 lib/table_sync/publishing/helpers/objects.rb
table_sync-6.0 lib/table_sync/publishing/helpers/objects.rb