action_subscriber 5.1.4.pre0-java → 5.1.5-java

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
- SHA1:
3
- metadata.gz: 593b4e50424f82a78fbeb6bf93c515c832cb32f3
4
- data.tar.gz: ed56497413a4a7b29cc4bfbe30e08b4323b2f4e8
2
+ SHA256:
3
+ metadata.gz: ca5face8fc684985f21cab2d0be98de2e2f6d8c56d08a403c62075291adbda8a
4
+ data.tar.gz: 3210c548ea05b9da02a358691434e22d875fcea6d11496959a849fee36223bfa
5
5
  SHA512:
6
- metadata.gz: 71e5c70d323ec56d6fe4ad8383672c6ecdcf3dfe6b745b79719b02523405e44dc310212bcf75685a3f9da79720749c45700533fe3606a6f07d883e52adc5dc6f
7
- data.tar.gz: bd8db80b1208d701df292dbc0eec9d98eb61892d245f4d5bdd12dbafc200b95c0980950e61038245c8c2cebaa1774b28597a90446db1ba2cae97c17a86beaf8e
6
+ metadata.gz: 2089e546d6494cf331f658b26d4ff57f35151ddf231e586082dd951e6f635f29d816fe0b3b2d7302f7fd25a5141e56dcc8f1e56909f3973a3b8ba86b908cb64a
7
+ data.tar.gz: 7f72c8204ed5bc09a61c1f3b62f6f5fb03bc21b66a6ca388f758c8bea776b93b6e275d99f0c77271652a0f0a3d7a3cb1692c237156d577aa47b67df5d36cbf69
@@ -1,9 +1,14 @@
1
1
  language: ruby
2
+ os:
3
+ linux
4
+ dist:
5
+ trusty
2
6
  rvm:
3
7
  - 2.2.6
4
8
  - 2.3.3
5
9
  - jruby-9.0.5.0
6
10
  - jruby-9.1.7.0
11
+ - jruby-9.1.12.0
7
12
  - jruby-head
8
13
  services:
9
14
  - rabbitmq
@@ -1,5 +1,38 @@
1
1
  module ActionSubscriber
2
2
  module DSL
3
+ class Filter
4
+ attr_accessor :callback_method
5
+ attr_accessor :included_actions
6
+ attr_accessor :excluded_actions
7
+
8
+ def initialize(callback_method, options)
9
+ @callback_method = callback_method
10
+ @included_actions = @excluded_actions = []
11
+ parse_options(options)
12
+ end
13
+
14
+ def matches(action)
15
+ unless included_actions.empty?
16
+ return included_actions.include?(action)
17
+ end
18
+
19
+ unless excluded_actions.empty?
20
+ return false if excluded_actions.include?(action)
21
+ end
22
+
23
+ true
24
+ end
25
+
26
+ private
27
+
28
+ def parse_options(options)
29
+ return unless options
30
+
31
+ @included_actions = options.fetch(:if, [])
32
+ @excluded_actions = options.fetch(:unless, [])
33
+ end
34
+ end
35
+
3
36
  def at_least_once!
4
37
  @_acknowledge_messages = true
5
38
  @_at_least_once = true
@@ -22,11 +55,16 @@ module ActionSubscriber
22
55
  !!@_acknowledge_messages
23
56
  end
24
57
 
25
- def around_filter(filter_method)
26
- around_filters << filter_method unless around_filters.include?(filter_method)
58
+ def around_filter(callback_method, options = nil)
59
+ filter = Filter.new(callback_method, options)
60
+ conditionally_add_filter!(filter)
27
61
  around_filters
28
62
  end
29
63
 
64
+ def conditionally_add_filter!(filter)
65
+ around_filters << filter unless around_filters.any? { |f| f.callback_method == filter.callback_method }
66
+ end
67
+
30
68
  def around_filters
31
69
  @_around_filters ||= []
32
70
  end
@@ -95,7 +133,11 @@ module ActionSubscriber
95
133
  final_block = Proc.new { subscriber_instance.public_send(action) }
96
134
 
97
135
  first_proc = around_filters.reverse.reduce(final_block) do |block, filter|
98
- Proc.new { subscriber_instance.send(filter, &block) }
136
+ if filter.matches(action)
137
+ Proc.new { subscriber_instance.send(filter.callback_method, &block) }
138
+ else
139
+ block
140
+ end
99
141
  end
100
142
  first_proc.call
101
143
  end
@@ -42,7 +42,7 @@ module ActionSubscriber
42
42
  @has_been_nacked = false
43
43
  @has_been_rejected = false
44
44
  @headers = properties.fetch(:headers, {})
45
- @message_id = properties.fetch(:message_id, ::SecureRandom.hex(3))
45
+ @message_id = properties[:message_id].presence || ::SecureRandom.hex(3)
46
46
  @queue = properties.fetch(:queue)
47
47
  @routing_key = properties.fetch(:routing_key)
48
48
  @subscriber = subscriber
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "5.1.4.pre0"
2
+ VERSION = "5.1.5"
3
3
  end
@@ -33,7 +33,7 @@ describe "subscriber filters", :integration => true do
33
33
  let(:subscriber) { InstaSubscriber }
34
34
 
35
35
  it "does not allow an around filter to be pushed on twice" do
36
- expect(InstaSubscriber.around_filters).to eq([:whisper, :yell])
36
+ expect(InstaSubscriber.around_filters.map(&:callback_method)).to eq([:whisper, :yell])
37
37
  end
38
38
 
39
39
  it "runs multiple around filters" do
@@ -46,3 +46,89 @@ describe "subscriber filters", :integration => true do
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ class OptionsSubscriber < ActionSubscriber::Base
51
+ around_filter :whisper, :if => [:primero, :segundo]
52
+ around_filter :yell, :if => [:primero]
53
+ around_filter :gossip, :unless => [:private_action]
54
+ around_filter :everybody
55
+
56
+ def primero
57
+ $messages << payload
58
+ end
59
+
60
+ def private_action
61
+ $messages << payload
62
+ end
63
+
64
+ def segundo
65
+ $messages << payload
66
+ end
67
+
68
+ private
69
+
70
+ def everybody
71
+ $messages << :everybody_before
72
+ yield
73
+ $messages << :everybody_after
74
+ end
75
+
76
+ def gossip
77
+ $messages << :gossip_before
78
+ yield
79
+ $messages << :gossip_after
80
+ end
81
+
82
+ def whisper
83
+ $messages << :whisper_before
84
+ yield
85
+ $messages << :whisper_after
86
+ end
87
+
88
+ def yell
89
+ $messages << :yell_before
90
+ yield
91
+ $messages << :yell_after
92
+ end
93
+ end
94
+
95
+ describe "subscriber filters with conditions", :integration => true do
96
+ let(:draw_routes) do
97
+ ::ActionSubscriber.draw_routes do
98
+ default_routes_for OptionsSubscriber
99
+ end
100
+ end
101
+ let(:subscriber) { OptionsSubscriber }
102
+
103
+ context "honors conditions" do
104
+ it "runs yell" do
105
+ $messages = []
106
+ ::ActionSubscriber.start_subscribers!
107
+ ::ActivePublisher.publish("options.primero", "Howdy!", "events")
108
+
109
+ verify_expectation_within(1.0) do
110
+ expect($messages).to eq [:whisper_before, :yell_before, :gossip_before, :everybody_before, "Howdy!", :everybody_after, :gossip_after, :yell_after, :whisper_after]
111
+ end
112
+ end
113
+
114
+ it "doesn't yell" do
115
+ $messages = []
116
+ ::ActionSubscriber.start_subscribers!
117
+ ::ActivePublisher.publish("options.segundo", "Howdy!", "events")
118
+
119
+ verify_expectation_within(1.0) do
120
+ expect($messages).to eq [:whisper_before, :gossip_before, :everybody_before, "Howdy!", :everybody_after, :gossip_after, :whisper_after]
121
+ end
122
+ end
123
+
124
+ it "doesn't gossip" do
125
+ $messages = []
126
+ ::ActionSubscriber.start_subscribers!
127
+ ::ActivePublisher.publish("options.private_action", "Howdy!", "events")
128
+
129
+ verify_expectation_within(1.0) do
130
+ expect($messages).to eq [:everybody_before, "Howdy!", :everybody_after]
131
+ end
132
+ end
133
+ end
134
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_subscriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.4.pre0
4
+ version: 5.1.5
5
5
  platform: java
6
6
  authors:
7
7
  - Brian Stien
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-11-30 00:00:00.000000000 Z
15
+ date: 2020-01-10 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  requirement: !ruby/object:Gem::Requirement
@@ -292,12 +292,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
292
292
  version: '0'
293
293
  required_rubygems_version: !ruby/object:Gem::Requirement
294
294
  requirements:
295
- - - ">"
295
+ - - ">="
296
296
  - !ruby/object:Gem::Version
297
- version: 1.3.1
297
+ version: '0'
298
298
  requirements: []
299
- rubyforge_project:
300
- rubygems_version: 2.6.13
299
+ rubygems_version: 3.1.2
301
300
  signing_key:
302
301
  specification_version: 4
303
302
  summary: ActionSubscriber is a DSL that allows a rails app to consume messages from