Sha256: 68de47c00ef9a89efbaaccf65d18c292af60a6dd1376861d14aaea0107e012e0

Contents?: true

Size: 902 Bytes

Versions: 26

Compression:

Stored size: 902 Bytes

Contents

module Praxis
  module RequestStages

    class Action < RequestStage

      def execute
        response = Notifications.instrument 'praxis.request_stage.execute'.freeze, controller: controller do
          if controller.method(action.name).arity == 0
            controller.__send__(action.name)
          else
            controller.__send__(action.name, **request.params_hash)
          end
        end

        case response
        when String
          controller.response.body = response
        when Praxis::Response
          controller.response = response
        else
          raise "Action #{action.name} in #{controller.class} returned #{response.inspect}. Only Response objects or Strings allowed."
        end
        controller.response.request = request
        nil # Action cannot return its OK request, as it would indicate the end of the stage chain
      end

    end

  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
praxis-2.0.pre.18 lib/praxis/request_stages/action.rb
praxis-2.0.pre.17 lib/praxis/request_stages/action.rb
praxis-2.0.pre.16 lib/praxis/request_stages/action.rb
praxis-2.0.pre.15 lib/praxis/request_stages/action.rb
praxis-2.0.pre.14 lib/praxis/request_stages/action.rb
praxis-2.0.pre.13 lib/praxis/request_stages/action.rb
praxis-2.0.pre.12 lib/praxis/request_stages/action.rb
praxis-2.0.pre.11 lib/praxis/request_stages/action.rb
praxis-2.0.pre.10 lib/praxis/request_stages/action.rb
praxis-2.0.pre.9 lib/praxis/request_stages/action.rb
praxis-2.0.pre.8 lib/praxis/request_stages/action.rb
praxis-2.0.pre.7 lib/praxis/request_stages/action.rb
praxis-2.0.pre.6 lib/praxis/request_stages/action.rb
praxis-2.0.pre.5 lib/praxis/request_stages/action.rb
praxis-2.0.pre.4 lib/praxis/request_stages/action.rb
praxis-2.0.pre.3 lib/praxis/request_stages/action.rb
praxis-2.0.pre.2 lib/praxis/request_stages/action.rb
praxis-2.0.pre.1 lib/praxis/request_stages/action.rb
praxis-0.22.pre.2 lib/praxis/request_stages/action.rb
praxis-0.22.pre.1 lib/praxis/request_stages/action.rb