Sha256: 6067607a8a849444c71c7c321a55d8ad7f8aa9a905948773a00e827012ac578d

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Azeroth
  class RequestHandler
    # @api private
    #
    # hadler for requests to update resource
    class Update < RequestHandler
      private

      # @private
      #
      # Updates and return an instance of the model
      #
      # update uses the method +"#{model.name}_params"+ to
      # fetch all allowed attributes for update
      #
      # @return [Object]
      def resource
        @resource ||= update_resource
      end

      # build resource for update
      #
      # @return [Object]
      def update_resource
        attributes = controller.send("#{model.name}_params")

        controller.send(model.name).tap do |entry|
          entry.update(attributes)
        end
      end

      # @private
      #
      # Response status
      #
      # For success, returns +:ok+, for
      # validation errors, it returns +:unprocessable_entity+
      #
      # @return [Symbol]
      def status
        resource.valid? ? :ok : :unprocessable_entity
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
azeroth-0.6.5 lib/azeroth/request_handler/update.rb
azeroth-0.6.4 lib/azeroth/request_handler/update.rb
azeroth-0.6.3 lib/azeroth/request_handler/update.rb
azeroth-0.6.2 lib/azeroth/request_handler/update.rb
azeroth-0.6.1 lib/azeroth/request_handler/update.rb
azeroth-0.6.0 lib/azeroth/request_handler/update.rb
azeroth-0.5.0 lib/azeroth/request_handler/update.rb
azeroth-0.4.0 lib/azeroth/request_handler/update.rb