Sha256: 3b8b42232ad1cba465b265e1be11f246ceabd9b32f00e4dbf912773fd0df16ea

Contents?: true

Size: 724 Bytes

Versions: 4

Compression:

Stored size: 724 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 Create < Pragma::Operation::Base
      include Pragma::Operation::Defaults

      def call
        record = build_record
        contract = build_contract(record)

        validate! contract
        authorize! contract

        contract.save

        respond_with resource: decorate(record)
      end

      protected

      # Builds the requested record.
      #
      # @return [Object]
      def build_record
        self.class.model_klass.new
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pragma-0.1.3 lib/pragma/operation/create.rb
pragma-0.1.2 lib/pragma/operation/create.rb
pragma-0.1.1 lib/pragma/operation/create.rb
pragma-0.1.0 lib/pragma/operation/create.rb