Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ruby 1.9 and 1.8 compatibility

  • Loading branch information...
commit 1eeb6f4a0e1aee7505d8a9280cd8e063760d81d8 1 parent 4f5dae7
Andre Lewis authored
Showing with 11 additions and 5 deletions.
  1. +11 −5 zz_archive/rabbitmq_overall/rabbitmq_overall.rb
View
16 zz_archive/rabbitmq_overall/rabbitmq_overall.rb
@@ -14,14 +14,14 @@ def build_report
begin
report_data = {}
- connection_stats = `#{rabbitmqctl} -q list_connections`.lines.to_a
+ connection_stats = string_to_lines(`#{rabbitmqctl} -q list_connections`)
report_data['connections'] = connection_stats.size
report_data['queues'] = report_data['messages'] = report_data['queue_mem'] = 0
report_data['exchanges'] = 0
report_data['bindings'] = 0
vhosts.each do |vhost|
- queue_stats = `#{rabbitmqctl} -q list_queues -p '#{vhost}' messages memory`.lines.to_a
+ queue_stats = string_to_lines(`#{rabbitmqctl} -q list_queues -p '#{vhost}' messages memory`)
report_data['queues'] += queue_stats.size
report_data['messages'] += queue_stats.inject(0) do |sum, line|
sum += line.split[0].to_i
@@ -31,10 +31,10 @@ def build_report
sum += line.split[1].to_i
end
- exchange_stats = `#{rabbitmqctl} -q list_exchanges -p #{vhost}`.lines.to_a
+ exchange_stats = string_to_lines(`#{rabbitmqctl} -q list_exchanges -p #{vhost}`)
report_data['exchanges'] += exchange_stats.size
- binding_stats = `#{rabbitmqctl} -q list_bindings -p #{vhost}`.lines.to_a
+ binding_stats = string_to_lines(`#{rabbitmqctl} -q list_bindings -p #{vhost}`)
report_data['bindings'] += binding_stats.size
end
@@ -52,7 +52,7 @@ def rabbitmqctl
end
def vhosts
- @vhosts ||= `#{rabbitmqctl} -q list_vhosts`.lines.to_a.map {|vhost| vhost.chomp }
+ @vhosts ||= string_to_lines(`#{rabbitmqctl} -q list_vhosts`).map {|vhost| vhost.chomp }
end
def `(command)
@@ -62,4 +62,10 @@ def `(command)
end
result
end
+
+ # for 1.8 & 1.9 compatability
+ def string_to_lines(s)
+ s.send(s.respond_to?(:lines) ? :lines : :to_s).to_a
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.