Module: ActionSubscriber::DSL

Included in:
Base
Defined in:
lib/action_subscriber/dsl.rb

Instance Method Summary collapse

Instance Method Details

#acknowledge_messages?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/action_subscriber/dsl.rb', line 13

def acknowledge_messages?
  !!@_acknowledge_messages
end

#around_filter(filter_method) ⇒ Object



17
18
19
# File 'lib/action_subscriber/dsl.rb', line 17

def around_filter(filter_method)
  around_filters << filter_method
end

#around_filtersObject



21
22
23
# File 'lib/action_subscriber/dsl.rb', line 21

def around_filters
  @_around_filters ||= []
end

#at_least_once!Object



3
4
5
6
# File 'lib/action_subscriber/dsl.rb', line 3

def at_least_once!
  @_acknowledge_messages = true
  around_filter :_at_least_once_filter
end

#at_most_once!Object



8
9
10
11
# File 'lib/action_subscriber/dsl.rb', line 8

def at_most_once!
  @_acknowledge_messages = true
  around_filter :_at_most_once_filter
end

#exchange_names(*names) ⇒ Object Also known as: exchange

Explicitly set the name of the exchange



27
28
29
30
31
32
33
34
35
36
# File 'lib/action_subscriber/dsl.rb', line 27

def exchange_names(*names)
  @_exchange_names ||= []
  @_exchange_names += names.flatten.map(&:to_s)

  if @_exchange_names.empty?
    return [ ::ActionSubscriber.config.default_exchange ]
  else
    return @_exchange_names.compact.uniq
  end
end

#manual_acknowledgement!Object



39
40
41
# File 'lib/action_subscriber/dsl.rb', line 39

def manual_acknowledgement!
  @_acknowledge_messages = true
end

#no_acknowledgement!Object



43
44
45
# File 'lib/action_subscriber/dsl.rb', line 43

def no_acknowledgement!
  @_acknowledge_messages = false
end

#queue_for(method, queue_name) ⇒ Object

Explicitly set the name of a queue for the given method route

Ex.

queue_for :created, "derp.derp"
queue_for :updated, "foo.bar"


53
54
55
56
# File 'lib/action_subscriber/dsl.rb', line 53

def queue_for(method, queue_name)
  @_queue_names ||= {}
  @_queue_names[method] = queue_name
end

#queue_namesObject



58
59
60
# File 'lib/action_subscriber/dsl.rb', line 58

def queue_names
  @_queue_names ||= {}
end

#remote_application_name(name = nil) ⇒ Object Also known as: publisher



62
63
64
65
# File 'lib/action_subscriber/dsl.rb', line 62

def remote_application_name(name = nil)
  @_remote_application_name = name if name
  @_remote_application_name
end

#routing_key_for(method, routing_key_name) ⇒ Object

Explicitly set the whole routing key to use for a given method route.



70
71
72
73
# File 'lib/action_subscriber/dsl.rb', line 70

def routing_key_for(method, routing_key_name)
  @_routing_key_names ||= {}
  @_routing_key_names[method] = routing_key_name
end

#routing_key_namesObject



75
76
77
# File 'lib/action_subscriber/dsl.rb', line 75

def routing_key_names
  @_routing_key_names ||= {}
end

#run_action_with_filters(env, action) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/action_subscriber/dsl.rb', line 79

def run_action_with_filters(env, action)
  subscriber_instance = self.new(env)
  final_block = Proc.new { subscriber_instance.public_send(action) }

  first_proc = around_filters.reverse.reduce(final_block) do |block, filter|
    Proc.new { subscriber_instance.send(filter, &block) }
  end
  first_proc.call
end