Sha256: 95b4ba4e732713dfdb16fbfabebea35ecacf90d6424afa5fe8c4f44076a2bbb9

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

module Crystal
  module Processors    
    class ControllerCaller < Processor
      attr_accessor :result_variable
      
      def initialize next_processor, result_variable = 'content'
        result_variable.must_be.present
        
        super(next_processor)                
        @result_variable = result_variable
      end
      
      def call                
        # prepare
        klass = workspace.class.must_be.present
        raise "The controller class #{klass} must be a Crystal::AbstractController!" unless klass.is? Crystal::AbstractController
        controller = workspace.controller = klass.new                  
        action = workspace.action = workspace.method_name
        format = workspace.params.format

        # call
        special_result = catch :special_result do
          controller.run_callbacks :action, :method => action do          
            # call controller
            controller.send action
            # render view
            workspace[result_variable] = controller.render_action :action => action          
          end
        end
        
        if special_result
          workspace[result_variable] = special_result
        else
          workspace[result_variable].must_be.defined
        end        
      end          
    
    end    
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

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