Skip to content

Commit

Permalink
Clean up nesting implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Jul 16, 2008
1 parent b5127c7 commit 99e8240
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions lib/data_fabric.rb
Expand Up @@ -48,27 +48,18 @@ def self.init

def self.activate_shard(shards, &block)
ensure_setup
old_shard_values = {}
newly_added_shard_keys = []

# Save the old shard settings to handle nested activation
old = Thread.current[:shards].dup

shards.each_pair do |key, value|
key = key.to_s
if Thread.current[:shards].has_key?(key)
old_shard_values[key] = Thread.current[:shards][key]
else
newly_added_shard_keys << key
end
Thread.current[:shards][key.to_s] = value.to_s
end
if block_given?
begin
yield
ensure
old_shard_values.each_pair do |key, value|
Thread.current[:shards][key] = value
end
newly_added_shard_keys.each do |key|
Thread.current[:shards].delete(key)
end
Thread.current[:shards] = old
end
end
end
Expand Down

0 comments on commit 99e8240

Please sign in to comment.