google-pubsub-enhancer 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba67939da32ef5c6324914f3aa8cfb2c109680e3
4
- data.tar.gz: b2959c127347710bb94de27eb23a73a4f0c505c1
3
+ metadata.gz: b0d68888960869040e10aadf51b0d4b2cc624636
4
+ data.tar.gz: 06040d4f23968fe94dc9f2f57cdc3f172c7fed42
5
5
  SHA512:
6
- metadata.gz: d332874e1c4459c1547d910e476f8b26dfb0c20fdfc349bdd0d429236e9c621b9094a803afa4fc5b54b34a1e6913a291eae9588befaf3daccceb6238522e394a
7
- data.tar.gz: 969e6b3dfd83e15a973cfb19cc459b9ae64fd985d8d9bf25d0b9bb65311d89550c7f660a9b7419f96af566d2b572fd6ae9b020f5889beb5ff7103b356ed61844
6
+ metadata.gz: c1d0e02a113ca4f975635a7e65fa13983daf586783547022ebdc2d6f737c16f5243b0433e2d26526c4b67cad6cb317fa81538b6d12eb6b477c8f499c3f845597
7
+ data.tar.gz: bcb6be3867750466c3caaeb2c2a8985a3aac01a7b7da06905c67818dfe68ec376d917716674e2efd2061716aaa707160a034ffdf29b891dd9b73c58c5f087cca
data/README.md CHANGED
@@ -28,10 +28,12 @@ require 'google_pubsub_enhancer'
28
28
 
29
29
  app = GooglePubsubEnhancer.new do
30
30
 
31
+ # you can get your messages from env[:received_messages]
32
+ # Be aware of the messages you got are pubsub objects. You van get your messages by calling map(&:data) on it.
31
33
  use YourMiddleware
32
34
  use GooglePubsubEnhancer::Publisher,
33
35
  short_topic_name: short_topic_name,
34
- messages: messages
36
+ messages: messages_key_you_declare
35
37
  end
36
38
 
37
39
  app.run(subscription_name)
@@ -42,6 +44,43 @@ app.run(subscription_name)
42
44
 
43
45
  To configure how much message should be pulled, use the GOOGLE_PUBSUB_ENHANCER_MAX_PULL_SIZE env variable with an integer value
44
46
 
47
+ ## Test
48
+
49
+ You can test your enhancer like:
50
+
51
+ ```ruby
52
+ require 'spec_helper'
53
+
54
+ describe YourApplication do
55
+
56
+ include GooglePubsubEnhancer::Spec
57
+
58
+ #the only user specific setting you need
59
+ let(:messages) {[{foo:1}, {bar:2}]}
60
+
61
+ it "should do the magic you write into" do
62
+
63
+ app = GooglePubsubEnhancer.new do
64
+
65
+ # in this case the test middleware creates messages from pubsub objects
66
+ use YourMiddleware, -> env do
67
+ env[:messages_key] = env[:received_messages].map(&:data)
68
+ end
69
+
70
+ use GooglePubsubEnhancer::Middleware::Publisher,
71
+ short_topic_name: 'short_topic_name',
72
+ messages: :messages_key
73
+ end
74
+
75
+ # the only expectation you need (further more you can check the)
76
+ expect(publisher).to receive(:publish).with({foo:1}).ordered
77
+ expect(publisher).to receive(:publish).with({bar:2}).ordered
78
+
79
+ app.run 'subscription_short_name'
80
+ end
81
+ end
82
+ ```
83
+
45
84
  ## Development
46
85
 
47
86
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,25 @@
1
+ module GooglePubsubEnhancer::Spec
2
+ module ClassMethods
3
+ def __setup_pubsub!
4
+ let(:messages) { [] }
5
+ let(:pubsub) {double "pubsub"}
6
+ let(:publisher) { double "publisher"}
7
+ let(:subscription) { double 'subscription'}
8
+ before do
9
+ allow(ENV).to receive(:[]).with("PUBSUB_KEYFILE_JSON").and_return(JSON.dump({project_id: 'cica'}))
10
+ allow(Google::Cloud::Pubsub).to receive(:new).and_return(pubsub)
11
+ allow(pubsub).to receive(:publish).and_yield(publisher)
12
+ allow(pubsub).to receive(:subscription).and_return subscription
13
+ allow(subscription).to receive(:pull).and_return(messages.map { |m| Google::Cloud::Pubsub::Message.new(m.to_s)},nil)
14
+ allow(publisher).to receive(:publish)
15
+ allow(subscription).to receive(:acknowledge)
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.included(klass)
21
+ klass.extend ClassMethods
22
+ klass.__setup_pubsub!
23
+ end
24
+
25
+ end
@@ -1,3 +1,3 @@
1
1
  class GooglePubsubEnhancer
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -4,8 +4,9 @@ require 'google/cloud/pubsub'
4
4
 
5
5
  class GooglePubsubEnhancer
6
6
 
7
- require_relative 'google_pubsub_enhancer/constants'
8
- require_relative 'google_pubsub_enhancer/middleware'
7
+ require 'google_pubsub_enhancer/constants'
8
+ require 'google_pubsub_enhancer/middleware'
9
+ require 'google_pubsub_enhancer/spec'
9
10
 
10
11
  class << self
11
12
  def name_by(type, name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-pubsub-enhancer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bejczib
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-30 00:00:00.000000000 Z
11
+ date: 2017-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,6 +104,7 @@ files:
104
104
  - lib/google_pubsub_enhancer/middleware/logger.rb
105
105
  - lib/google_pubsub_enhancer/middleware/logger/duration.rb
106
106
  - lib/google_pubsub_enhancer/middleware/publisher.rb
107
+ - lib/google_pubsub_enhancer/spec.rb
107
108
  - lib/google_pubsub_enhancer/version.rb
108
109
  homepage: http://github.com/bejczib/google-pubsub-enhancer
109
110
  licenses: