Sha256: 70086da572e1c4a2b0da84cdc120f5c76fd7db996d3483767fafd293133925f9

Contents?: true

Size: 890 Bytes

Versions: 6

Compression:

Stored size: 890 Bytes

Contents

require 'mercury'
require 'mercury/cps'

class Mercury
  class Monadic

    def self.open(**kws)
      Cps.new do |&k|
        Mercury.open(**kws) do |m|
          k.call(new(m))
        end
      end
    end

    def self.wrap(method_name)
      define_method(method_name) do |*args, **kws, &block|
        Cps.new do |&k|
          if @mercury.method(method_name).parameters.map(&:first).include?(:key)
            @mercury.send(method_name, *[*args, *block], **kws, &k)
          else
            @mercury.send(method_name, *[*args, *block], &k)
          end
        end
      end
    end

    wrap(:publish)
    wrap(:republish)
    wrap(:start_listener)
    wrap(:start_worker)
    wrap(:delete_source)
    wrap(:delete_work_queue)
    wrap(:source_exists?)
    wrap(:queue_exists?)
    wrap(:close)

    private
    def initialize(mercury)
      @mercury = mercury
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mercury_amqp-0.9.0 lib/mercury/monadic.rb
mercury_amqp-0.8.0 lib/mercury/monadic.rb
mercury_amqp-0.7.0 lib/mercury/monadic.rb
mercury_amqp-0.6.1 lib/mercury/monadic.rb
mercury_amqp-0.6.0 lib/mercury/monadic.rb
mercury_amqp-0.5.0 lib/mercury/monadic.rb