Sha256: 44f3930ae83f489e30e5a23d8cf11b25cf441567fbd855c5c099668b7fc1eeed

Contents?: true

Size: 735 Bytes

Versions: 7

Compression:

Stored size: 735 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
        record = find_record
        contract = build_contract(record)

        validate! contract
        authorize! contract

        contract.save

        respond_with resource: decorate(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

7 entries across 7 versions & 1 rubygems

Version Path
pragma-1.0.0 lib/pragma/operation/update.rb
pragma-0.2.0 lib/pragma/operation/update.rb
pragma-0.1.4 lib/pragma/operation/update.rb
pragma-0.1.3 lib/pragma/operation/update.rb
pragma-0.1.2 lib/pragma/operation/update.rb
pragma-0.1.1 lib/pragma/operation/update.rb
pragma-0.1.0 lib/pragma/operation/update.rb