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-22.1.1.pre lib/lhs/concerns/item/destroy.rb
lhs-22.1.0 lib/lhs/concerns/item/destroy.rb
lhs-22.0.0 lib/lhs/concerns/item/destroy.rb
lhs-21.3.1 lib/lhs/concerns/item/destroy.rb
lhs-21.3.0 lib/lhs/concerns/item/destroy.rb
lhs-21.3.0.pre.autoauth.1 lib/lhs/concerns/item/destroy.rb
lhs-21.2.4 lib/lhs/concerns/item/destroy.rb
lhs-21.2.3 lib/lhs/concerns/item/destroy.rb
lhs-21.2.3.pre.preload.pre.providers.pre.too.1 lib/lhs/concerns/item/destroy.rb
lhs-21.2.2 lib/lhs/concerns/item/destroy.rb
lhs-21.2.1 lib/lhs/concerns/item/destroy.rb
lhs-21.2.0 lib/lhs/concerns/item/destroy.rb
lhs-21.1.4 lib/lhs/concerns/item/destroy.rb
lhs-21.1.3 lib/lhs/concerns/item/destroy.rb
lhs-21.1.2 lib/lhs/concerns/item/destroy.rb
lhs-21.1.2.pre.keyfix.2 lib/lhs/concerns/item/destroy.rb
lhs-21.1.2.pre.keyfix.1 lib/lhs/concerns/item/destroy.rb
lhs-21.1.2.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 lib/lhs/concerns/item/destroy.rb
lhs-21.1.1.pre.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 lib/lhs/concerns/item/destroy.rb
lhs-21.1.0 lib/lhs/concerns/item/destroy.rb