_perform_save

in lib/aws-record/record/item_operations.rb [246:293]


      def _perform_save(opts)
        force = opts.delete(:force)
        expect_new = expect_new_item?
        if force
          put_opts = {
            table_name: self.class.table_name,
            item: _build_item_for_save
          }
          dynamodb_client.put_item(opts.merge(put_opts))
        elsif expect_new
          put_opts = {
            table_name: self.class.table_name,
            item: _build_item_for_save
          }.merge(prevent_overwrite_expression)
          begin
            dynamodb_client.put_item(opts.merge(put_opts))
          rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException => e
            raise Errors::ConditionalWriteFailed.new(
              'Conditional #put_item call failed! Check that conditional write ' \
              'conditions are met, or include the :force option to clobber ' \
              'the remote item.',
              e
            )
          end
        else
          update_opts = {
            table_name: self.class.table_name,
            key: key_values
          }
          update_pairs = _dirty_changes_for_update
          update_expression_opts = self.class.send(
            :_build_update_expression,
            update_pairs
          )
          opts = self.class.send(
            :_merge_update_expression_opts,
            update_expression_opts,
            opts
          )
          resp = dynamodb_client.update_item(opts.merge(update_opts))
          assign_attributes(resp[:attributes]) if resp[:attributes]
        end
        data = instance_variable_get('@data')
        data.destroyed = false
        data.new_record = false
        true
      end