messaging 3.5.4 → 3.6.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
  SHA256:
3
- metadata.gz: d7666c410d9615fbc6485721b8a58fa9955bbae59e0b4398998ea8ebcaaea2cf
4
- data.tar.gz: 2047edef3c30faa65b313f7000676a1d15bc7a4738e732582f9bde56852d5c2e
3
+ metadata.gz: 7733bdd43c5aadf3544db1993e9b5e4c48fe3f8b08aa1f22f52c7677f203a4d3
4
+ data.tar.gz: b72f6b61afec8c0815f52bd81559eb01e0f7c9ac8f00e98b3f9985f84994b0fe
5
5
  SHA512:
6
- metadata.gz: b2f35e80e2ffdd4b8159732ebfbd543cb597b03fc9569da9c5aab26fac05bf216c150b427e902e448da56c96e2eb3feb7e76e5b9d73e370decb9a3eb0bb067b6
7
- data.tar.gz: 4f73eae45aaaa94b2ca1fc9443028c49e20bbc7ccc96e3913e36593176b8c1088d53e85a11d97ab89ea240f317c0efc47bfa5bdbab93cc70e423f6bf14b20258
6
+ metadata.gz: 93f6bee9427950094427800eedbf0ee071de5b8e0a6bafc7ed23a45c85112360d7695fb7d0c0b94b085d504aaf007d4fb647e97b374d20436dd3a26ed02848ca
7
+ data.tar.gz: b3e9858b73d47d38f7935e0232598e202ef4c834e3183111f376783d4b677c7d680e915efa3da041152cc29ab4329b93478c5dd9d0f595c534f6c8733f0798ed
data/Gemfile CHANGED
@@ -3,14 +3,14 @@ source 'https://rubygems.org'
3
3
  git_source(:github) { |path| "https://github.com/#{path}.git" }
4
4
 
5
5
  gem 'bootsnap', require: false
6
- gem 'listen'
6
+ #gem 'listen'
7
7
  gem 'pg'
8
8
  gem 'pry'
9
9
  gem 'pry-rails'
10
10
  gem 'railties'
11
11
  gem 'sidekiq'
12
12
 
13
- gem "github-pages", '203', group: :jekyll_plugins
14
- gem "jekyll-include-cache", group: :jekyll_plugins
13
+ #gem "github-pages", '203', group: :jekyll_plugins
14
+ #gem "jekyll-include-cache", group: :jekyll_plugins
15
15
 
16
16
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- messaging (3.5.4)
4
+ messaging (3.5.7)
5
5
  activerecord
6
6
  activesupport
7
7
  after_transaction
@@ -2,7 +2,7 @@ module Messaging
2
2
  module Adapters
3
3
  class Postgres
4
4
  class SerializedMessage < ActiveRecord::Base
5
- self.table_name = :messaging_messages
5
+ self.table_name = 'messaging.messages'
6
6
 
7
7
  attr_accessor :expected_version
8
8
 
@@ -5,6 +5,12 @@ module Messaging
5
5
  # @return [String] the name of the stream
6
6
  attr_reader :name
7
7
 
8
+ # @return [String] the stream category
9
+ attr_reader :category
10
+
11
+ # @return [String] the stream id
12
+ attr_reader :id
13
+
8
14
  # Should not be used directly.
9
15
  # Use {Messaging.stream} or {Store#stream}
10
16
  # @api private
@@ -12,12 +18,13 @@ module Messaging
12
18
  # @see Store.stream
13
19
  def initialize(name)
14
20
  @name = name
21
+ @category, @id = name.split('$')
15
22
  end
16
23
 
17
24
  # Access to all messages in the stream sorted by stream_position
18
25
  # @return [ActiveRecord::Relation]
19
26
  def messages
20
- SerializedMessage.where(stream: name).order(:stream_position)
27
+ SerializedMessage.where(stream_category: category, stream_id: id).order(:stream_position)
21
28
  end
22
29
 
23
30
  # The current position of the last message in the stream
@@ -25,6 +25,32 @@ module Messaging
25
25
  end
26
26
 
27
27
  module ClassMethods
28
+ # The stream that the message will be stored in when published.
29
+ #
30
+ # Stream names consists of the stream category and the stream id separated by a $.
31
+ # For instance "customer$123" where "customer" is the category and "123" is the id.
32
+ #
33
+ # When no stream name is given the message will not be persisted in the message store.
34
+ #
35
+ # @param [#call,String,nil] name The name of the stream, will be evaluated in the context
36
+ # of the message instance.
37
+ #
38
+ # @example
39
+ # class CustomerRegistered
40
+ # include Messaging::Message
41
+ #
42
+ # stream_name -> { "customer$#{customer_id}"}
43
+ #
44
+ # attribute :customer_id, Integer
45
+ # end
46
+ #
47
+ # CustomerRegistered.new(customer_id: 123).stream_name
48
+ # # => "customer$123"
49
+ def stream_name(name = nil)
50
+ return @stream_name unless name
51
+ @stream_name = name
52
+ end
53
+
28
54
  # By default the topic is the same as the name of the message.
29
55
  # We change the / that would be set for a namespaced message as "/" isn't valid in a topic
30
56
  # To change the topic for a message just set it to whatever you want in your class definition.
@@ -88,8 +114,8 @@ module Messaging
88
114
  end
89
115
 
90
116
  def stream_name
91
- # define stream_name in your message class to override
92
- nil
117
+ return unless self.class.stream_name
118
+ instance_exec(&self.class.stream_name)
93
119
  end
94
120
 
95
121
  def stream_category
@@ -31,6 +31,10 @@ module Messaging
31
31
  Messaging.routes.reload_consumer_routes!
32
32
  end
33
33
  end
34
+
35
+ config.to_prepare do
36
+ Messaging.routes.finalize_routes
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -51,7 +51,18 @@ module Messaging
51
51
 
52
52
  # Public: Evaluate route definition.
53
53
  def draw(&block)
54
- instance_eval(&block)
54
+ routing_definition_blocks << block
55
+ end
56
+
57
+ def routing_definition_blocks
58
+ @routing_definition_blocks ||= []
59
+ end
60
+
61
+ def finalize_routes
62
+ clear_routes!
63
+ routing_definition_blocks.each do |block|
64
+ instance_eval(&block)
65
+ end
55
66
  end
56
67
 
57
68
  private
@@ -1,3 +1,3 @@
1
1
  module Messaging
2
- VERSION = '3.5.4'.freeze
2
+ VERSION = '3.6.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.4
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bukowskis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-27 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -273,7 +273,6 @@ files:
273
273
  - ".circleci/config.yml"
274
274
  - ".gitignore"
275
275
  - ".rspec"
276
- - ".ruby-version"
277
276
  - Gemfile
278
277
  - Gemfile.lock
279
278
  - README.md
@@ -351,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
351
350
  - !ruby/object:Gem::Version
352
351
  version: '0'
353
352
  requirements: []
354
- rubygems_version: 3.0.6
353
+ rubygems_version: 3.0.3.1
355
354
  signing_key:
356
355
  specification_version: 4
357
356
  summary: A library for decoupling applications by using messaging to communicate between
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.3.1