Sha256: 63a4c7065c19ca073eb4504650a431146e0ec7acdf973315f170c7191625a403

Contents?: true

Size: 791 Bytes

Versions: 3

Compression:

Stored size: 791 Bytes

Contents

# frozen_string_literal: true
module Pragma
  module Operation
    # Finds the requested record, authorizes it, updates it accordingly to the parameters and
    # responds with the decorated record.
    #
    # @author Alessandro Desantis
    class Update < Pragma::Operation::Base
      include Pragma::Operation::Defaults

      def call
        context.record = find_record
        context.contract = build_contract(context.record)

        validate! context.contract
        authorize! context.contract

        context.contract.save

        respond_with resource: decorate(context.record)
      end

      protected

      # Finds the requested record.
      #
      # @return [Object]
      def find_record
        self.class.model_klass.find(params[:id])
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pragma-1.1.2 lib/pragma/operation/update.rb
pragma-1.1.1 lib/pragma/operation/update.rb
pragma-1.1.0 lib/pragma/operation/update.rb