Sha256: 9d4084cac705d14be4988333bc55a24e33991c3dbc59754ecf00c9bf84537108

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

module Rad
  module HttpController
    inherit AbstractController
    
    # def response
    #   workspace.response
    # end
    
    protected
      def render_with_parsed_arguments options, original_args                 
        response = workspace.response
        response.set!(
          status: options.status || :ok, 
          content_type: options.content_type || Mime[params.format]
        )
        
        if original_args.size == 1 and (status = Rad::Response.decode_status_message(original_args.first))          
          response.set! status: status
          throw :halt_render, ""
        elsif options.location?
          redirect_to options.location
        else          
          super
        end
      end
    
    module ClassMethods      
      inheritable_accessor :actions_allowed_for_get_request, []
      
      def allow_get_for *methods
        enable_protection_from_get_requests!        
        actions_allowed_for_get_request.push *methods
      end
      
      private
        def enable_protection_from_get_requests!
          unless respond_to? :protect_from_get_request
            define_method :protect_from_get_request do
              if workspace.request.get? and !self.class.actions_allowed_for_get_request.include?(workspace.action)
                raise "Get requests not allowed for :#{workspace.action} action!"
              end            
            end
            before :protect_from_get_request
          end
        end
    end
  end
end    

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rad_core-0.0.13 lib/rad/controller/http_controller.rb