Class: Marples::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/marples/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Client



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/marples/client.rb', line 8

def initialize *args
  if args[0].kind_of? Hash
    options = args.shift
    self.transport = options[:transport]
    self.client_name = options[:client_name]
    self.logger = options[:logger]
  else
    self.transport = args.shift
    self.client_name = args.shift
    self.logger = args.shift
    logger.warn "Positional arguments to Marples::Client#new are " + \
      "deprecated and will be removed."
  end
  raise "You must provide a transport" if transport.nil?
  self.logger = NullLogger.instance if logger.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(action, *args) ⇒ Object



30
31
32
33
# File 'lib/marples/client.rb', line 30

def method_missing action, *args
  return super unless args.size == 1
  publish action, args[0]
end

Instance Method Details

#joinObject



25
26
27
28
# File 'lib/marples/client.rb', line 25

def join
  logger.debug "Listening on #{transport}"
  transport.join
end

#payload_for(klass, &block) ⇒ Object



69
70
71
# File 'lib/marples/client.rb', line 69

def payload_for klass, &block
  payload_generator[klass] = block
end

#when(application, object_type, action) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/marples/client.rb', line 35

def when application, object_type, action
  logger.info "Listening for #{application} notifiying us of #{action} #{object_type}"
  destination = destination_for application, object_type, action
  logger.debug "Underlying destination is #{destination}"
  transport.subscribe destination do |message|
    logger.info "Received message #{message.headers['message-id']} from #{destination}"
    #logger.debug "Message body: #{message.body}"
    hash = Hash.from_xml message.body
    #logger.debug "Constructed hash: #{hash.inspect}"
    attributes = hash.values[0]
    #logger.debug "Yielding hash: #{attributes.inspect}"
    logger.info("About to yield")

    yield attributes
    logger.info "Finished processing message #{message.headers['message-id']}"
  end
end