Sha256: 8bf19aaa9a79f8eedb45ebc4f6817e16453416e5dcea0259af1bf42e72fc3f19

Contents?: true

Size: 976 Bytes

Versions: 2

Compression:

Stored size: 976 Bytes

Contents

module Telegram
  module Bot
    class UpdatesController
      module Testing
        IVARS_TO_KEEP = %i[@_session].freeze

        # Perform multiple dispatches on same instance.
        def dispatch_again(bot = nil, update = nil, webhook_request = nil)
          recycle!
          initialize(bot, update, webhook_request)
          dispatch
        end

        # Cleans controller between dispatches.
        # Seems like there is nothing to clean between requests for now:
        # everything will be rewriten with #initialize.
        #
        # With `full` set to `true` it'll clear all cached instance variables.
        def recycle!(full = false)
          return unless full
          (instance_variables - IVARS_TO_KEEP).each do |ivar|
            remove_instance_variable(ivar)
          end
        end

        protected

        # Stubs session.
        def session
          @_session ||= Session::NullSessionHash.new
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
telegram-bot-0.16.1 lib/telegram/bot/updates_controller/testing.rb
telegram-bot-0.16.0 lib/telegram/bot/updates_controller/testing.rb