- all_exchanges(vhost).each do |line|
- name, type, internal, durable, auto_delete, arguments = line.split
- if type.nil?
- # if name is empty, it will wrongly get the type's value.
- # This way type will get the correct value
- type = name
- name = ''
- end
- # Convert output of arguments from the rabbitmqctl command to a json string.
- if !arguments.nil?
- arguments = arguments.gsub(%r{^\[(.*)\]$}, '').gsub(%r{\{("(?:.|\\")*?"),}, '{\1:').gsub(%r{\},\{}, ',')
- arguments = '{}' if arguments == ''
- else
- arguments = '{}'
+ all_exchanges(vhost).each do |line|
+ name, type, internal, durable, auto_delete, arguments = line.split()
+ if type.nil?
+ # if name is empty, it will wrongly get the type's value.
+ # This way type will get the correct value
+ type = name
+ name = ''
+ end
+ # Convert output of arguments from the rabbitmqctl command to a json string.
+ if !arguments.nil?
+ arguments = arguments.gsub(/^\[(.*)\]$/, "").gsub(/\{("(?:.|\\")*?"),/, '{\1:').gsub(/\},\{/, ",")
+ if arguments == ""
+ arguments = '{}'
+ end
+ else
+ arguments = '{}'
+ end
+ exchange = {
+ :type => type,
+ :ensure => :present,
+ :internal => internal,
+ :durable => durable,
+ :auto_delete => auto_delete,
+ :name => "%s@%s" % [name, vhost],
+ :arguments => JSON.parse(arguments),
+ }
+ resources << new(exchange) if exchange[:type]