Sha256: 7fea71c751a97e01164b9c4e92204367e37ae933c0c80d259e1e47bf5b0a0763

Contents?: true

Size: 1010 Bytes

Versions: 12

Compression:

Stored size: 1010 Bytes

Contents

# frozen_string_literal: true

require 'active_support'

class DHS::Item < DHS::Proxy

  module Destroy
    extend ActiveSupport::Concern

    def destroy(options = {})
      options ||= {}
      options = options.merge(method: :delete)
      data = _data._raw.dup
      url = url_for_deletion!(options, data)
      options = options.merge(url: url)
      _data._request = _data.class.request(options)._request
      _data
    end

    private

    def url_for_deletion!(options, data)
      return href if href.present?
      endpoint = endpoint_for_deletion(data, options)
      endpoint.compile(
        merge_data_with_options(data, options)
      ).tap do
        endpoint.remove_interpolated_params!(data)
        endpoint.remove_interpolated_params!(options.fetch(:params, {}))
        options.merge!(endpoint.options.merge(options)) if endpoint.options
      end
    end

    def endpoint_for_deletion(data, options)
      record.find_endpoint(merge_data_with_options(data, options))
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 lib/dhs/concerns/item/destroy.rb
dhs-1.5.0 lib/dhs/concerns/item/destroy.rb
dhs-1.4.2 lib/dhs/concerns/item/destroy.rb
dhs-1.4.1 lib/dhs/concerns/item/destroy.rb
dhs-1.4.0 lib/dhs/concerns/item/destroy.rb
dhs-1.3.0 lib/dhs/concerns/item/destroy.rb
dhs-1.2.0 lib/dhs/concerns/item/destroy.rb
dhs-1.1.0 lib/dhs/concerns/item/destroy.rb
dhs-1.0.3 lib/dhs/concerns/item/destroy.rb
dhs-1.0.2 lib/dhs/concerns/item/destroy.rb
dhs-1.0.1 lib/dhs/concerns/item/destroy.rb
dhs-1.0.0 lib/dhs/concerns/item/destroy.rb