Sha256: a90b07bf42e3d3d3f44789f9c43cf67e14a3e43d1e711bf4c39343d8963b14fb

Contents?: true

Size: 1 KB

Versions: 8

Compression:

Stored size: 1 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
        controller.send(model.name).tap do |entry|
          trigger_event(:save) do
            entry.update(attributes)
          end
        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.8.2 lib/azeroth/request_handler/update.rb
azeroth-0.8.1 lib/azeroth/request_handler/update.rb
azeroth-0.8.0 lib/azeroth/request_handler/update.rb
azeroth-0.7.4 lib/azeroth/request_handler/update.rb
azeroth-0.7.3 lib/azeroth/request_handler/update.rb
azeroth-0.7.2 lib/azeroth/request_handler/update.rb
azeroth-0.7.1 lib/azeroth/request_handler/update.rb
azeroth-0.7.0 lib/azeroth/request_handler/update.rb