Sha256: 05a9d14729ea16965565df76cf9aed1da57a65d5f057bced573d56f973b4beac

Contents?: true

Size: 822 Bytes

Versions: 2

Compression:

Stored size: 822 Bytes

Contents

# Example:
# RosettaQueue::Filters.define do |filter_for|
#   filter_for.receiving { |message| JSON.parse(message) }
#   filter_for.sending { |hash| hash.to_json }
# end


module RosettaQueue
  class Filters
    
    class << self
            
      def define
        yield self
      end
      
      def reset
        @receiving = nil
        @sending = nil
      end
    
      def receiving(&receiving_filter)
        @receiving = receiving_filter
      end
    
      def sending(&sending_filter)
        @sending = sending_filter
      end
      
      def process_sending(message)
        return message unless @sending
        @sending.call(message)
      end
      
      def process_receiving(message)
        return message unless @receiving
        @receiving.call(message)
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
bmabey-rosetta_queue-0.2.0 lib/rosetta_queue/filters.rb
cwyckoff-rosetta_queue-0.3.3 lib/rosetta_queue/filters.rb