Sha256: 82e57d204481a89408ce89d4b9ca44fdceae372fcba2e1b2180fde9701118d7c

Contents?: true

Size: 1.34 KB

Versions: 32

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'active_support'

class LHS::Item < LHS::Proxy
  autoload :EndpointLookup,
    'lhs/concerns/item/endpoint_lookup'

  module Update
    extend ActiveSupport::Concern

    included do
      include EndpointLookup
    end

    def update(params, options = nil, partial_update = false)
      update!(params, options, partial_update)
    rescue LHC::Error => e
      self.errors = LHS::Problems::Errors.new(e.response, record)
      false
    end

    def partial_update(params, options = nil)
      update(params, options, true)
    end

    def partial_update!(params, options = nil)
      update!(params, options, true)
    end

    def update!(params, options = {}, partial_update = false)
      options = options.present? ? options.dup : {}
      partial_record = _record.new(LHS::Data.new(params, _data.parent, _record))
      _data.merge_raw!(partial_record._data)
      data = _data._raw.dup
      partial_data = partial_record._data._raw.dup
      url = url_for_persistance!(data, options)
      data_sent = partial_update ? partial_data.extract!(*data.keys) : data
      response_data = record.request(
        options.merge(
          method: options.fetch(:method, :post),
          url: url,
          body: data_sent
        )
      )
      _data.merge_raw!(response_data.unwrap(:item_created_key))
      true
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
lhs-26.2.0 lib/lhs/concerns/item/update.rb
lhs-26.1.0 lib/lhs/concerns/item/update.rb
lhs-26.0.1 lib/lhs/concerns/item/update.rb
lhs-26.0.0 lib/lhs/concerns/item/update.rb
lhs-25.2.0 lib/lhs/concerns/item/update.rb
lhs-25.1.0 lib/lhs/concerns/item/update.rb
lhs-25.0.4 lib/lhs/concerns/item/update.rb
lhs-25.0.3 lib/lhs/concerns/item/update.rb
lhs-25.0.2 lib/lhs/concerns/item/update.rb
lhs-25.0.1 lib/lhs/concerns/item/update.rb
lhs-25.0.0 lib/lhs/concerns/item/update.rb
lhs-24.1.2 lib/lhs/concerns/item/update.rb
lhs-24.1.1 lib/lhs/concerns/item/update.rb
lhs-24.1.0 lib/lhs/concerns/item/update.rb
lhs-24.1.0.pre.2 lib/lhs/concerns/item/update.rb
lhs-24.1.0.pre.1 lib/lhs/concerns/item/update.rb
lhs-24.0.0 lib/lhs/concerns/item/update.rb
lhs-23.0.2 lib/lhs/concerns/item/update.rb
lhs-23.0.1 lib/lhs/concerns/item/update.rb
lhs-23.0.0 lib/lhs/concerns/item/update.rb