Sha256: 28ca75054afd5f05891ef434d9cf4f5380b4500dbd9cbfd52eed72c0dd43b5fb
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
module RabbitMQ::Definition class Dump < Command def initialize(client, verbose, vhosts = nil) super(client, verbose) @vhosts = vhosts || FileDefinition.read.vhosts.map { |vhost| vhost['name'] } end def execute FileDefinition.new(filter_and_order_list_definition).tap do |definition| Logger.info definition.to_json if verbose Logger.progress "Saving definition..." definition.save Logger.success "Done" end end private def filter_and_order_list_definition client.list_definitions.reduce({}) do |result, (key, value)| value = case key when "vhosts" @vhosts.sort.map {|name| {'name' => name} } when "queues", "exchanges" filter_vhosts(value).sort do |a, b| [a["vhost"], a["name"]] <=> [b["vhost"], b["name"]] end when "bindings" filter_vhosts(value).sort do |a, b| [a["vhost"], a["source"], a["destination"], a["routing_key"]] <=> [b["vhost"], b["source"], b["destination"], b["routing_key"]] end else value end result[key] = value result end end def filter_vhosts(items) items.reduce([]) do |array, item| array.push(item) if @vhosts.include?(item["vhost"]) array end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rabbitmq-definition-0.1.3 | lib/rabbitmq_definition/dump.rb |
rabbitmq-definition-0.1.2 | lib/rabbitmq_definition/dump.rb |