Sha256: 62119d69232df8bbe293b4c52a802a47600ae8fd56cb3d1762c20a215d340d14

Contents?: true

Size: 1010 Bytes

Versions: 70

Compression:

Stored size: 1010 Bytes

Contents

# frozen_string_literal: true

require 'active_support'

class LHS::Item < LHS::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

70 entries across 70 versions & 1 rubygems

Version Path
lhs-19.3.0 lib/lhs/concerns/item/destroy.rb
lhs-19.2.0 lib/lhs/concerns/item/destroy.rb
lhs-19.1.0 lib/lhs/concerns/item/destroy.rb
lhs-19.0.2 lib/lhs/concerns/item/destroy.rb
lhs-19.0.1 lib/lhs/concerns/item/destroy.rb
lhs-19.0.0 lib/lhs/concerns/item/destroy.rb
lhs-19.0.0.pre.endpoint.1 lib/lhs/concerns/item/destroy.rb
lhs-18.0.3 lib/lhs/concerns/item/destroy.rb
lhs-18.0.2 lib/lhs/concerns/item/destroy.rb
lhs-18.0.1 lib/lhs/concerns/item/destroy.rb