Sha256: ddecbe2a375e94ff1185ed9889829a5957656869dd0c1ddaea5e166b58fc51d5

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require "delegate"

require "pakyow/support/core_refinements/string/normalization"
require "pakyow/support/hookable"

module Pakyow
  class Application
    class Connection < SimpleDelegator
      attr_reader :app

      include Support::Hookable
      events :initialize, :dup

      require "pakyow/application/connection/behavior/session"
      require "pakyow/application/connection/behavior/verifier"
      require "pakyow/application/connection/behavior/values"

      include Behavior::Session
      include Behavior::Verifier
      include Behavior::Values

      using Support::Refinements::String::Normalization

      def initialize(app, connection)
        performing :initialize do
          @app = app; __setobj__(connection)
        end
      end

      def initialize_dup(_)
        performing :dup do
          super
        end
      end

      def path
        unless instance_variable_defined?(:@path)
          @path = String.normalize_path(
            __getobj__.path.split(@app.mount_path, 2)[1]
          )
        end

        @path
      end

      def method
        __getobj__.method
      end

      # Fixes an issue using pp inside a delegator.
      #
      def pp(*args)
        Kernel.pp(*args)
      end

      # @api private
      def self.from_connection(connection, **overrides)
        instance = allocate

        connection.instance_variables.each do |ivar|
          instance.instance_variable_set(ivar, overrides[ivar] || connection.instance_variable_get(ivar))
        end

        instance
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pakyow-core-1.0.6 lib/pakyow/application/connection.rb
pakyow-core-1.0.5 lib/pakyow/application/connection.rb
pakyow-core-1.0.4 lib/pakyow/application/connection.rb
pakyow-core-1.0.3 lib/pakyow/application/connection.rb
pakyow-core-1.0.2 lib/pakyow/application/connection.rb