lib/tasks/switchman.rake in switchman-1.4.2 vs lib/tasks/switchman.rake in switchman-1.4.3

- old
+ new

@@ -3,20 +3,26 @@ def self.filter_database_servers(&block) chain = filter_database_servers_chain # use a local variable so that the current chain is closed over in the following lambda @filter_database_servers_chain = lambda { |servers| block.call(servers, chain) } end - def self.scope(base_scope = Shard) + def self.scope(base_scope = Shard, + database_server: ENV['DATABASE_SERVER'], + shard: ENV['SHARDS']) servers = DatabaseServer.all - if ENV['DATABASE_SERVER'] - servers = ENV['DATABASE_SERVER'] + if database_server + servers = database_server if servers.first == '-' negative = true servers = servers[1..-1] end - servers = servers.split(',').map { |server| DatabaseServer.find(server) }.compact + servers = servers.split(',') + open = servers.delete('open') + + servers = servers.map { |server| DatabaseServer.find(server) }.compact + servers.concat(DatabaseServer.all.select { |server| server.config[:open] }) if open servers = DatabaseServer.all - servers if negative end servers = filter_database_servers_chain.call(servers) @@ -25,11 +31,11 @@ conditions = ["database_server_id IN (?)", servers.map(&:id)] conditions.first << " OR database_server_id IS NULL" if servers.include?(Shard.default.database_server) scope = scope.where(conditions) end - if ENV['SHARD'] - scope = shard_scope(scope, ENV['SHARD']) + if shard + scope = shard_scope(scope, shard) end scope end