Sha256: 1e3a74a9100e47361c0f7fa8d7a7066cffc96e1ef1f67dac6d63a2f8884e74dd

Contents?: true

Size: 631 Bytes

Versions: 12

Compression:

Stored size: 631 Bytes

Contents

module CubaApi
  module ResponseStatus
    def response_status( obj, options = {})
      if options[:response_status] != false
        if obj.respond_to?( :errors ) && obj.errors.size > 0
          res.status = 412 # Precondition Failed
          obj = obj.errors
        elsif req.post?
          res.status = 201 # Created
          res[ 'Location' ] = env[ 'SCRIPT_NAME' ] + "/#{obj.id}" if obj.respond_to? :id
        elsif req.delete?
          res.status = 204 # No Content
          obj = ''
        end
      end
      obj
    end

    def self.included( base )
      base.prepend_aspect :response_status
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cuba-api-0.6.3 lib/cuba_api/response_status.rb~
cuba-api-0.6.2 lib/cuba_api/response_status.rb~
cuba-api-0.6.1 lib/cuba_api/response_status.rb~
cuba-api-0.6.0 lib/cuba_api/response_status.rb~
cuba-api-0.5.1 lib/cuba_api/response_status.rb~
cuba-api-0.5.0 lib/cuba_api/response_status.rb~
cuba-api-0.4.0 lib/cuba_api/response_status.rb~
cuba-api-0.3.3 lib/cuba_api/response_status.rb~
cuba-api-0.3.2 lib/cuba_api/response_status.rb~
cuba-api-0.3.1 lib/cuba_api/response_status.rb~
cuba-api-0.3.0 lib/cuba_api/response_status.rb~
cuba-api-0.2.0 lib/cuba_api/response_status.rb~