Sha256: fa86f46fe83580dffdeb61fdd4a091afb26c380e253c358a07563557bb1ab61c

Contents?: true

Size: 1.84 KB

Versions: 7

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

require "pakyow/support/extension"

module Pakyow
  class Application
    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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pakyow-core-1.0.6 lib/pakyow/application/behavior/pipeline.rb
pakyow-core-1.0.5 lib/pakyow/application/behavior/pipeline.rb
pakyow-core-1.0.4 lib/pakyow/application/behavior/pipeline.rb
pakyow-core-1.0.3 lib/pakyow/application/behavior/pipeline.rb
pakyow-core-1.0.2 lib/pakyow/application/behavior/pipeline.rb
pakyow-core-1.0.1 lib/pakyow/application/behavior/pipeline.rb
pakyow-core-1.0.0 lib/pakyow/application/behavior/pipeline.rb