Sha256: 0e37c120b0b859e62d777fe2d2e88705b087c5defc6a7d11562179e8d6e1685b

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

require "pakyow/support/extension"

module Pakyow
  module Behavior
    # Loads default pipeline actions based on included frameworks.
    #
    module Pipeline
      extend Support::Extension

      apply_extension do
        # We set the priority very low here in case initialize hooks in other frameworks define
        # state that should be loaded into the pipeline (e.g. controllers).
        #
        after "initialize", "initialize.pipeline", priority: -10 do
          self.class.__pipeline.dup.tap do |pipeline|
            load_pipeline_defaults(pipeline)
            @__pipeline = pipeline.callable(self)
          end
        end
      end

      private

      def load_pipeline_defaults(pipeline)
        if self.class.includes_framework?(:assets)
          pipeline.action(Actions::Assets::Public, self)
          pipeline.action(Actions::Assets::Process)
        end

        if self.class.includes_framework?(:realtime) && Pakyow.config.realtime.server && !is_a?(Plugin)
          pipeline.action(Actions::Realtime::Upgrader)
        end

        if self.class.includes_framework?(:routing) && !Pakyow.env?(:prototype)
          state(:controller).each do |controller|
            pipeline.action(controller, self)
          end
        end

        if instance_variable_defined?(:@plugs)
          @plugs.each do |plug_instance|
            pipeline.action(plug_instance)
          end
        end

        if self.class.includes_framework?(:presenter)
          pipeline.action(Actions::Presenter::AutoRender)
        end

        if self.class.includes_framework?(:routing) && !Pakyow.env?(:prototype) && !is_a?(Plugin)
          pipeline.action(Actions::Routing::RespondMissing)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pakyow-core-1.0.0.rc5 lib/pakyow/behavior/pipeline.rb
pakyow-core-1.0.0.rc4 lib/pakyow/behavior/pipeline.rb
pakyow-core-1.0.0.rc3 lib/pakyow/behavior/pipeline.rb