Sha256: 016ddee6af20370e5029e28867a07aa155b3eed8194e2b3b164e63f7dba347e7

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require "delegate"

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

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

      def initialize_dup(_)
        performing :dup do
          super
        end
      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

2 entries across 2 versions & 1 rubygems

Version Path
pakyow-core-1.0.1 lib/pakyow/application/connection.rb
pakyow-core-1.0.0 lib/pakyow/application/connection.rb