la_gear 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/la_gear/active_record/publish_triggerable.rb +11 -19
- data/lib/la_gear/bus.rb +0 -6
- data/lib/la_gear/version.rb +1 -1
- data/test/test_bus.rb +79 -6
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af0f62ca02e7a0d327d376e9d1e43c72819f5cbe
|
|
4
|
+
data.tar.gz: 164640b8a42d87770dc09c2eb4a73195e21cf502
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c87e0696e4d709d2332f01f4d0c77bcd1725e5114173f98c7aef887ade8af73fe41afa34e44e3d98bb010e8aef3cc6f87d24267ab152793a7f70f3f4a7181ec
|
|
7
|
+
data.tar.gz: 4fa5b3011ec6741c0531677777aa816fef663edcea671885f180334efb2a89343588763a703cc46d51b535060517c4b5da29f71bf6c818adde4377276211d083
|
|
@@ -3,50 +3,42 @@ module LaGear
|
|
|
3
3
|
module PublishTriggerable
|
|
4
4
|
def publish_after_commit(routing_key, opts)
|
|
5
5
|
publish_method = "publish_#{routing_key}"
|
|
6
|
-
la_gear_opts =
|
|
6
|
+
la_gear_opts = la_gear_options(opts)
|
|
7
7
|
define_method publish_method do
|
|
8
8
|
message = block_given? ? yield(self) : {}
|
|
9
9
|
Bus.publish(routing_key.to_s, message, la_gear_opts)
|
|
10
10
|
end
|
|
11
|
-
after_commit publish_method, opts
|
|
11
|
+
after_commit publish_method, after_commit_options(opts)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def send_after_commit(routing_key, opts)
|
|
15
15
|
publish_method = "publish_#{routing_key}"
|
|
16
|
-
la_gear_opts =
|
|
16
|
+
la_gear_opts = la_gear_options(opts)
|
|
17
17
|
define_method publish_method do
|
|
18
18
|
message = block_given? ? yield(self) : {}
|
|
19
19
|
Bus.publish_local(routing_key.to_s, message, la_gear_opts)
|
|
20
20
|
end
|
|
21
|
-
after_commit publish_method, opts
|
|
21
|
+
after_commit publish_method, after_commit_options(opts)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def send_in_after_commit(routing_key, opts, interval)
|
|
25
25
|
publish_method = "publish_#{routing_key}"
|
|
26
|
-
la_gear_opts =
|
|
26
|
+
la_gear_opts = la_gear_options(opts)
|
|
27
27
|
define_method publish_method do
|
|
28
28
|
message = block_given? ? yield(self) : {}
|
|
29
29
|
Bus.publish_local_in(routing_key.to_s, message, la_gear_opts, interval)
|
|
30
30
|
end
|
|
31
|
-
after_commit publish_method, opts
|
|
31
|
+
after_commit publish_method, after_commit_options(opts)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
private
|
|
35
35
|
|
|
36
|
-
def
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if opts.key?(:version)
|
|
40
|
-
la_gear_opts[:version] = opts[:version]
|
|
41
|
-
opts.delete(:version)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
if opts.key?(:suffix)
|
|
45
|
-
la_gear_opts[:suffix] = opts[:suffix]
|
|
46
|
-
opts.delete(:suffix)
|
|
47
|
-
end
|
|
36
|
+
def after_commit_options(opts = {})
|
|
37
|
+
opts.reject { |k, _v| [:version, :suffix].include?(k) }
|
|
38
|
+
end
|
|
48
39
|
|
|
49
|
-
|
|
40
|
+
def la_gear_options(opts = {})
|
|
41
|
+
opts.select { |k, _v| [:version, :suffix].include?(k) }
|
|
50
42
|
end
|
|
51
43
|
end
|
|
52
44
|
end
|
data/lib/la_gear/bus.rb
CHANGED
|
@@ -43,8 +43,6 @@ module LaGear
|
|
|
43
43
|
end
|
|
44
44
|
module_function :publish_local_in
|
|
45
45
|
|
|
46
|
-
private
|
|
47
|
-
|
|
48
46
|
class NamespaceUtility
|
|
49
47
|
class << self
|
|
50
48
|
def local_worker(routing_key)
|
|
@@ -54,17 +52,13 @@ module LaGear
|
|
|
54
52
|
def adjust_routing_key(routing_key, opts = {})
|
|
55
53
|
if opts.key?(:version)
|
|
56
54
|
routing_key = add_version(routing_key, opts[:version])
|
|
57
|
-
opts.delete(:version)
|
|
58
55
|
elsif opts.key?(:suffix)
|
|
59
56
|
routing_key = add_suffix(routing_key, opts[:suffix])
|
|
60
57
|
end
|
|
61
58
|
|
|
62
|
-
opts.delete(:suffix)
|
|
63
59
|
routing_key
|
|
64
60
|
end
|
|
65
61
|
|
|
66
|
-
private
|
|
67
|
-
|
|
68
62
|
def add_version(routing_key, version)
|
|
69
63
|
return add_suffix(routing_key, "v#{version}") if version.present?
|
|
70
64
|
routing_key
|
data/lib/la_gear/version.rb
CHANGED
data/test/test_bus.rb
CHANGED
|
@@ -209,6 +209,12 @@ class TestBus < LaGear::Test
|
|
|
209
209
|
must_invoke_publisher_with_must_invoke_publisher_publish
|
|
210
210
|
end
|
|
211
211
|
end
|
|
212
|
+
|
|
213
|
+
describe 'when method is called more than once' do
|
|
214
|
+
it 'does not modify the parameters' do
|
|
215
|
+
does_not_modify_parameters
|
|
216
|
+
end
|
|
217
|
+
end
|
|
212
218
|
end
|
|
213
219
|
end
|
|
214
220
|
|
|
@@ -397,6 +403,12 @@ class TestBus < LaGear::Test
|
|
|
397
403
|
must_invoke_publisher_with_must_invoke_publisher_publish
|
|
398
404
|
end
|
|
399
405
|
end
|
|
406
|
+
|
|
407
|
+
describe 'when method is called more than once' do
|
|
408
|
+
it 'does not modify the parameters' do
|
|
409
|
+
does_not_modify_parameters
|
|
410
|
+
end
|
|
411
|
+
end
|
|
400
412
|
end
|
|
401
413
|
end
|
|
402
414
|
|
|
@@ -585,6 +597,12 @@ class TestBus < LaGear::Test
|
|
|
585
597
|
must_invoke_publisher_with_must_invoke_publisher_publish
|
|
586
598
|
end
|
|
587
599
|
end
|
|
600
|
+
|
|
601
|
+
describe 'when method is called more than once' do
|
|
602
|
+
it 'does not modify the parameters' do
|
|
603
|
+
does_not_modify_parameters
|
|
604
|
+
end
|
|
605
|
+
end
|
|
588
606
|
end
|
|
589
607
|
end
|
|
590
608
|
|
|
@@ -652,6 +670,12 @@ class TestBus < LaGear::Test
|
|
|
652
670
|
it 'must invoke perform_async on the constantized routing_key' do
|
|
653
671
|
must_invoke_perform_method_on_the_constantized_routing_key
|
|
654
672
|
end
|
|
673
|
+
|
|
674
|
+
describe 'when method is called more than once' do
|
|
675
|
+
it 'does not modify the parameters' do
|
|
676
|
+
does_not_modify_parameters
|
|
677
|
+
end
|
|
678
|
+
end
|
|
655
679
|
end
|
|
656
680
|
end
|
|
657
681
|
|
|
@@ -720,11 +744,30 @@ class TestBus < LaGear::Test
|
|
|
720
744
|
it 'must invoke perform_async on the constantized routing_key' do
|
|
721
745
|
must_invoke_perform_method_on_the_constantized_routing_key
|
|
722
746
|
end
|
|
747
|
+
|
|
748
|
+
describe 'when method is called more than once' do
|
|
749
|
+
it 'does not modify the parameters' do
|
|
750
|
+
does_not_modify_parameters
|
|
751
|
+
end
|
|
752
|
+
end
|
|
723
753
|
end
|
|
724
754
|
end
|
|
725
755
|
|
|
726
756
|
private
|
|
727
757
|
|
|
758
|
+
def does_not_modify_parameters
|
|
759
|
+
expected_opts = @la_gear_opts.clone
|
|
760
|
+
args = [@base_routing_key, @expected_msg, @la_gear_opts]
|
|
761
|
+
args.unshift(@expected_timestamp) if defined?(@expected_timestamp)
|
|
762
|
+
if defined?(@expected_interval)
|
|
763
|
+
args.push(@expected_interval) if @bus_method == :publish_local_in
|
|
764
|
+
args.unshift(@expected_interval) if @bus_method == :publish_in
|
|
765
|
+
end
|
|
766
|
+
LaGear::Bus.public_send(@bus_method, *args)
|
|
767
|
+
LaGear::Bus.public_send(@bus_method, *args)
|
|
768
|
+
@la_gear_opts.must_equal(expected_opts)
|
|
769
|
+
end
|
|
770
|
+
|
|
728
771
|
def must_invoke_delayable_publisher_sidekiq_delay
|
|
729
772
|
expected_args = [{}]
|
|
730
773
|
expected_args.unshift(@expected_interval) if defined?(@expected_interval)
|
|
@@ -734,8 +777,11 @@ class TestBus < LaGear::Test
|
|
|
734
777
|
LaGear::Bus::DelayablePublisher.stub @sidekiq_delay_method, mock do
|
|
735
778
|
LaGear::Bus::DelayablePublisher.stub :publish, nil do
|
|
736
779
|
input_args = [@base_routing_key, @expected_msg, @la_gear_opts]
|
|
737
|
-
input_args.unshift(@expected_interval) if defined?(@expected_interval)
|
|
738
780
|
input_args.unshift(@expected_timestamp) if defined?(@expected_timestamp)
|
|
781
|
+
if defined?(@expected_interval)
|
|
782
|
+
input_args.push(@expected_interval) if @bus_method == :publish_local_in
|
|
783
|
+
input_args.unshift(@expected_interval) if @bus_method == :publish_in
|
|
784
|
+
end
|
|
739
785
|
LaGear::Bus.public_send(@bus_method, *input_args)
|
|
740
786
|
end
|
|
741
787
|
end
|
|
@@ -748,8 +794,13 @@ class TestBus < LaGear::Test
|
|
|
748
794
|
LaGear::Bus::DelayablePublisher.stub @sidekiq_delay_method, LaGear::Bus::DelayablePublisher do
|
|
749
795
|
LaGear::Bus::DelayablePublisher.stub :publish, mock do
|
|
750
796
|
args = [@base_routing_key, @expected_msg, @la_gear_opts]
|
|
751
|
-
|
|
797
|
+
|
|
752
798
|
args.unshift(@expected_timestamp) if defined?(@expected_timestamp)
|
|
799
|
+
if defined?(@expected_interval)
|
|
800
|
+
args.push(@expected_interval) if @bus_method == :publish_local_in
|
|
801
|
+
args.unshift(@expected_interval) if @bus_method == :publish_in
|
|
802
|
+
end
|
|
803
|
+
|
|
753
804
|
LaGear::Bus.send(@bus_method, *args)
|
|
754
805
|
end
|
|
755
806
|
end
|
|
@@ -762,8 +813,13 @@ class TestBus < LaGear::Test
|
|
|
762
813
|
LaGear::Bus::DelayablePublisher.stub @sidekiq_delay_method, LaGear::Bus::DelayablePublisher do
|
|
763
814
|
LaGear::Publisher.stub :new, mock do
|
|
764
815
|
args = [@base_routing_key, @expected_msg, @la_gear_opts]
|
|
765
|
-
|
|
816
|
+
|
|
766
817
|
args.unshift(@expected_timestamp) if defined?(@expected_timestamp)
|
|
818
|
+
if defined?(@expected_interval)
|
|
819
|
+
args.push(@expected_interval) if @bus_method == :publish_local_in
|
|
820
|
+
args.unshift(@expected_interval) if @bus_method == :publish_in
|
|
821
|
+
end
|
|
822
|
+
|
|
767
823
|
LaGear::Bus.send(@bus_method, *args)
|
|
768
824
|
end
|
|
769
825
|
end
|
|
@@ -775,8 +831,13 @@ class TestBus < LaGear::Test
|
|
|
775
831
|
$publisher.expect(:with, nil)
|
|
776
832
|
LaGear::Bus::DelayablePublisher.stub @sidekiq_delay_method, LaGear::Bus::DelayablePublisher do
|
|
777
833
|
args = [@base_routing_key, @expected_msg, @la_gear_opts]
|
|
778
|
-
|
|
834
|
+
|
|
779
835
|
args.unshift(@expected_timestamp) if defined?(@expected_timestamp)
|
|
836
|
+
if defined?(@expected_interval)
|
|
837
|
+
args.push(@expected_interval) if @bus_method == :publish_local_in
|
|
838
|
+
args.unshift(@expected_interval) if @bus_method == :publish_in
|
|
839
|
+
end
|
|
840
|
+
|
|
780
841
|
LaGear::Bus.send(@bus_method, *args)
|
|
781
842
|
end
|
|
782
843
|
$publisher.verify
|
|
@@ -788,8 +849,13 @@ class TestBus < LaGear::Test
|
|
|
788
849
|
mock.expect(:publish, nil, [@expected_msg, { to_queue: @expected_routing_key }])
|
|
789
850
|
LaGear::Bus::DelayablePublisher.stub @sidekiq_delay_method, LaGear::Bus::DelayablePublisher do
|
|
790
851
|
args = [@base_routing_key, @expected_msg, @la_gear_opts]
|
|
791
|
-
|
|
852
|
+
|
|
792
853
|
args.unshift(@expected_timestamp) if defined?(@expected_timestamp)
|
|
854
|
+
if defined?(@expected_interval)
|
|
855
|
+
args.push(@expected_interval) if @bus_method == :publish_local_in
|
|
856
|
+
args.unshift(@expected_interval) if @bus_method == :publish_in
|
|
857
|
+
end
|
|
858
|
+
|
|
793
859
|
LaGear::Bus.send(@bus_method, *args)
|
|
794
860
|
end
|
|
795
861
|
mock.verify
|
|
@@ -798,11 +864,18 @@ class TestBus < LaGear::Test
|
|
|
798
864
|
def must_invoke_perform_method_on_the_constantized_routing_key
|
|
799
865
|
expected_args = @expected_msg.values
|
|
800
866
|
expected_args.unshift(@expected_interval) if defined?(@expected_interval)
|
|
867
|
+
expected_args.unshift(@expected_timestamp) if defined?(@expected_timestamp)
|
|
801
868
|
mock = MiniTest::Mock.new
|
|
802
869
|
mock.expect(:call, nil, expected_args)
|
|
803
870
|
@local_worker.stub @perform_method, mock do
|
|
804
871
|
input_args = [@base_routing_key, @expected_msg, @la_gear_opts]
|
|
805
|
-
|
|
872
|
+
|
|
873
|
+
input_args.unshift(@expected_timestamp) if defined?(@expected_timestamp)
|
|
874
|
+
if defined?(@expected_interval)
|
|
875
|
+
input_args.push(@expected_interval) if @bus_method == :publish_local_in
|
|
876
|
+
input_args.unshift(@expected_interval) if @bus_method == :publish_in
|
|
877
|
+
end
|
|
878
|
+
|
|
806
879
|
LaGear::Bus.send(@bus_method, *input_args)
|
|
807
880
|
end
|
|
808
881
|
mock.verify
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: la_gear
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gabriel Chaney
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2015-07-
|
|
13
|
+
date: 2015-07-17 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: json
|