Sha256: 8c15daa4d6e6f666a758b3c462463bd0a86d836992365f347f0f9504ebfdb04b

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

module Crystal
  module HttpController
    inherit AbstractController
    
    protected
      def render_with_parsed_arguments options
        if options.content_type?
          workspace.response.content_type = options.content_type
          super
        elsif options.location?
          response = workspace.response
          response.location, response.status = options.location, (options.status || 301)            
          throw :special_result, %(<html><body>You are being <a href="#{options.location.html_escape}">redirected</a>.</body></html>)
        elsif options.status?  
          workspace.response.status = options.status          
          super
        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.collect(&:to_s)
      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

3 entries across 3 versions & 2 rubygems

Version Path
crystal-0.0.13 lib/crystal/controller/http_controller.rb
crystal-0.0.12 lib/crystal/controller/http_controller.rb
crystal_ext-0.0.11 lib/crystal/controller/http_controller.rb