Sha256: 6e5281f2199302d23e41282b2810cc907a1f24c1dd1bfabb95514b05e7d86889

Contents?: true

Size: 1.94 KB

Versions: 14

Compression:

Stored size: 1.94 KB

Contents

# -*- encoding: utf-8 -*-

# Mixin for {OnStomp::Client clients} to create frame scopes.
module OnStomp::Components::Scopes
  # Creates a new {OnStomp::Components::Scopes::ReceiptScope}.
  # Any receipt-able frame generated on this scope will automatically have
  # the supplied callback attached as a RECEIPT handler.
  # @yield [r] callback to be invoked when the RECEIPT frame is received
  # @yieldparam [OnStomp::Components::Frame] r RECEIPT frame
  # @return [OnStomp::Components::Scopes::ReceiptScope]
  def with_receipt &block
    OnStomp::Components::Scopes::ReceiptScope.new(block, self)
  end
  
  # Creates a new {OnStomp::Components::Scopes::TransactionScope} and
  # evaluates the block within that scope if one is given.
  # @param [String] tx_id optional id for the transaction
  # @yield [t] block of frames to generate within a transaction
  # @yieldparam [OnStomp::Components::Scopes::TransactionScope] t
  # @return [OnStomp::Components::Scopes::TransactionScope]
  # @see OnStomp::Components::Scopes::TransactionScope#perform
  def transaction tx_id=nil, &block
    OnStomp::Components::Scopes::TransactionScope.new(tx_id, self).tap do |t|
      t.perform(&block) if block
    end
  end
  
  # Creates a new {OnStomp::Components::Scopes::HeaderScope} that
  # will apply the provided headers to all frames generated on the scope.
  # If a block is given, it will be evaluated within this scope.
  # @param [{#to_sym => #to_s}] headers
  # @yield [h] block of frames to apply headers to
  # @yieldparam [OnStomp::Components::Scopes::HeaderScope] h
  # @return [OnStomp::Components::Scopes::HeaderScope]
  # @see OnStomp::Components::Scopes::HeaderScope#perform
  def with_headers headers
    OnStomp::Components::Scopes::HeaderScope.new(headers, self).tap do |h|
      yield h if block_given?
    end
  end
end

require 'onstomp/components/scopes/header_scope'
require 'onstomp/components/scopes/receipt_scope'
require 'onstomp/components/scopes/transaction_scope'

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
onstomp-1.0.12 lib/onstomp/components/scopes.rb
onstomp-1.0.11 lib/onstomp/components/scopes.rb
onstomp-1.0.10 lib/onstomp/components/scopes.rb
onstomp-1.0.9 lib/onstomp/components/scopes.rb
onstomp-1.0.8 lib/onstomp/components/scopes.rb
onstomp-1.0.7 lib/onstomp/components/scopes.rb
onstomp-1.0.6 lib/onstomp/components/scopes.rb
onstomp-1.0.5 lib/onstomp/components/scopes.rb
onstomp-1.0.4 lib/onstomp/components/scopes.rb
onstomp-1.0.3 lib/onstomp/components/scopes.rb
onstomp-1.0.2 lib/onstomp/components/scopes.rb
onstomp-1.0.1 lib/onstomp/components/scopes.rb
onstomp-1.0.0 lib/onstomp/components/scopes.rb
onstomp-1.0.0pre1 lib/onstomp/components/scopes.rb