Module: StartHer::Subscriber::ClassMethods

Defined in:
lib/start_her/subscriber.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#subscriber_error_blockObject

Returns the value of attribute subscriber_error_block.



15
16
17
# File 'lib/start_her/subscriber.rb', line 15

def subscriber_error_block
  @subscriber_error_block
end

#subscriber_options_hashObject

Returns the value of attribute subscriber_options_hash.



15
16
17
# File 'lib/start_her/subscriber.rb', line 15

def subscriber_options_hash
  @subscriber_options_hash
end

Instance Method Details

#run!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/start_her/subscriber.rb', line 17

def run!
  new.tap do |instance|
    instance.psubscribe(subscriber_options_hash[:channels]) do |channel, message|
      begin
        instance.process_message(channel, message)
      rescue => e
        if block_given?
          subscriber_error_block.call(e)
        else
          DEFAULT_ERROR_BLOCK.call(e)
        end
      end
    end
  end
end

#subscriber_error(&block) ⇒ Object



33
34
35
# File 'lib/start_her/subscriber.rb', line 33

def subscriber_error(&block)
  self.subscriber_error_block = block
end

#subscriber_options(opts = {}) ⇒ Object



37
38
39
# File 'lib/start_her/subscriber.rb', line 37

def subscriber_options(opts = {})
  self.subscriber_options_hash = DEFAULT_OPTS.merge(opts)
end