Sha256: 73c7c95ba4f0db5abd57878ead938166c1385aa2ffd10f32887e63a0086031d4

Contents?: true

Size: 739 Bytes

Versions: 11

Compression:

Stored size: 739 Bytes

Contents

module StripeLocal
	module Webhook

		#
		# basically taken straight from the StripeEvents gem
		# https://github.com/integrallis/stripe_event
		#
		#
	  class Subscriber
	    def initialize *names, &block
	      @names = names
	      @block = block
	      ensure_valid_types!
	    end

	    def register
	      ActiveSupport::Notifications.subscribe(pattern) do |_, _, _, _, payload|
	        @block.call payload[:event]
	      end
	    end

	    private

	    def pattern
	      Regexp.union(@names.empty? ? TYPE_LIST : @names)
	    end

	    def ensure_valid_types!
	      invalid_names = @names.select { |name| !TYPE_LIST.include?(name) }
	      raise InvalidEventType.new(invalid_names) if invalid_names.any?
	    end
	  end
	end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
stripe_local-0.2.5 lib/stripe_local/webhook/subscriber.rb
stripe_local-0.2.4 lib/stripe_local/webhook/subscriber.rb
stripe_local-0.2.3 lib/stripe_local/webhook/subscriber.rb
stripe_local-0.2.2 lib/stripe_local/webhook/subscriber.rb
stripe_local-0.2.1 lib/stripe_local/webhook/subscriber.rb
stripe_local-0.2.0 lib/stripe_local/webhook/subscriber.rb
stripe_local-0.1.3 lib/stripe_local/webhook/subscriber.rb
stripe_local-0.1.2 lib/stripe_local/webhook/subscriber.rb
stripe_local-0.1.1 lib/stripe_local/webhook/subscriber.rb
stripe_local-0.1.0 lib/stripe_local/webhook/subscriber.rb
stripe_local-0.0.2 lib/stripe_local/webhook/subscriber.rb