Class: PaymentKit::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/payment_kit/namespace.rb

Overview

Prefixes notification names and builds subscription regexes.

Events instrument as payment_kit.<type>.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix) ⇒ Namespace

prefix is prepended to every event type, and should end with a dot.



9
10
11
# File 'lib/payment_kit/namespace.rb', line 9

def initialize(prefix)
  @prefix = prefix.to_s
end

Instance Attribute Details

#prefixObject (readonly)

The configured prefix, e.g. "payment_kit.".



14
15
16
# File 'lib/payment_kit/namespace.rb', line 14

def prefix
  @prefix
end

Instance Method Details

#call(name) ⇒ Object

Returns the fully namespaced notification name for an event type.



17
18
19
# File 'lib/payment_kit/namespace.rb', line 17

def call(name)
  "#{@prefix}#{name}"
end

#to_regexp(name = nil) ⇒ Object

+nil+/empty name matches the entire namespace (used by PaymentKit.all).



22
23
24
25
# File 'lib/payment_kit/namespace.rb', line 22

def to_regexp(name = nil)
  pattern = name.nil? || name.to_s.empty? ? @prefix : "#{@prefix}#{name}"
  /\A#{Regexp.escape(pattern)}/
end