Permalink
Browse files

Expose WAPN.batch_all

  • Loading branch information...
1 parent 1e60a23 commit decab78282499db91f9aa86de3884f3de0ba500a @nevir nevir committed Apr 5, 2012
Showing with 24 additions and 2 deletions.
  1. +7 −0 lib/wapn/configuration.rb
  2. +8 −2 lib/wapn/provider.rb
  3. +9 −0 spec/configuration_spec.rb
@@ -15,6 +15,13 @@ def provider(name)
attr_reader :providers
+ # Sets up a batch for *all* configured providers. Go wild!
+ def batch_all(&block)
+ self.providers.values.each(&:begin_batch)
+ block.call
+ self.providers.values.each(&:commit_batch)
+ end
+
# ## WAPN.load_config
#
# Reads a config from YAML file, or passed as a Hash. The configuration is a map of provider
View
@@ -154,10 +154,16 @@ def notify(device_or_devices, payload_or_options)
# Collects a batch of notifications from calls to `notify`, and bulk sends them when the block
# returns.
def batch(&block)
- @batch = []
-
+ self.begin_batch
block.call
+ self.commit_batch
+ end
+
+ def begin_batch
+ @batch = []
+ end
+ def commit_batch
self.send_notifications(@batch)
@batch = nil
end
@@ -53,6 +53,15 @@
provider.logger.level.should == Logger::DEBUG
end
+ it "should provide a batch_all helper" do
+ root.providers.values.each do |provider|
+ provider.should_receive(:begin_batch).once
+ provider.should_receive(:commit_batch).once
+ end
+
+ root.batch_all { }
+ end
+
end
end

0 comments on commit decab78

Please sign in to comment.