stenotype 0.1.5 → 0.1.10

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: 78f28a1322b09dc099de1351779e15e67247ad5010c907b0cf99efb05e9c3ca4
4
- data.tar.gz: 949901992d1c976941ca306154f546292bbd7f0df0bcb21a27a4458daa0dcd59
3
+ metadata.gz: fd4b1f727ef1c544ff5df02cc9162f69831e27105e89095d0b6b533cdddb0e05
4
+ data.tar.gz: 0ae2c31943e14b6752fe418afd9bbb031622bbf7119b69381529ee9620b93226
5
5
  SHA512:
6
- metadata.gz: 18e3d0ea81fc68afbe99cf5da1569e2c87c1819c30430fcc1f23c23b6cb201767cf35885d7d2a643ac3bf284b8ee00d5e26644a08ab0ace902b863fff4f0527e
7
- data.tar.gz: 63a868b627122e6c46f6b920b6b237f2fa7c88c1827ef7946e226868644a80e43a0c4c9a89e66dfec4909ca54bc53cc7b5c534bf8a9972621016521ffb1faeab
6
+ metadata.gz: 25753465eeeb0b876f72e548e81e2707bb12080aba5fbaa531db8d9ac1d4006f8bd0e9a83692d1996b2b7fed9b2f392c70748a89752ec24b5e524f559909e002
7
+ data.tar.gz: 0deacdeb626e43e3415fb398098f864ec2337b50642cae156e928839a307dbbafd9f23e828c7f94367af0ea809910e1a7b645799853ed76d268755357bdf2aba
@@ -0,0 +1,41 @@
1
+ name: RSpec
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby:
11
+ - "2.6.x"
12
+ rails:
13
+ - "5.2.0"
14
+ - "6.0.0"
15
+
16
+ steps:
17
+ - uses: actions/checkout@v1
18
+ - uses: actions/cache@v1
19
+ with:
20
+ path: vendor/bundle
21
+ key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ hashFiles('**/Gemfile.lock') }}
22
+ restore-keys: |
23
+ ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}
24
+ - name: Set up Ruby ${{ matrix.ruby }}
25
+ uses: actions/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ - name: Apply Rails ${{ matrix.rails }} dependencies
29
+ run: |
30
+ echo "gem 'rails', '~> ${{ matrix.rails }}'" >> Gemfile
31
+ - name: Set up dependencies
32
+ env:
33
+ BUNDLE_GEM__FURY__IO: ${{ secrets.GEMFURY_DEPLOY_TOKEN }}
34
+ run: |
35
+ gem install bundler
36
+ bundle config path vendor/bundle
37
+ bundle update rails --jobs 4 --retry 3
38
+ bundle install --jobs 4 --retry 3
39
+ - name: Run RSpec
40
+ run: |
41
+ bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  *Release Date*: 2020/01/13
4
4
 
5
+ ### 0.1.10
6
+ Switch from Spicerack::Configurable to Spicerack::Directive
7
+
8
+ ### 0.1.9
9
+ * Pass all attributes in the data field instead of attributes field for google cloud. Attributes field did not allow nested objects, which data field allows. See google pub sub documentation for more reference.
10
+
11
+ ### 0.1.8
12
+ * Switch auto target initialization to false
13
+
14
+ ### 0.1.7 2020/01/20
15
+ * Adds a config option to allow explicit adapter setup.
16
+ * Adds an `after_initialize` rails hook to setup adapters.
17
+ * Remove topic from the list of Google Cloud adapter arguments.
18
+
19
+ ### 0.1.6 2020/01/17
20
+ * Allow topic to be explicitly set upon Google Cloud adapter initialization
21
+
5
22
  ### 0.1.5 2020/01/13
6
23
  * In case `graceful_error_handling` is set to off raise a generic `Stenotype::Error` on any exception in order to intercept a single error type in the client code.
7
24
  * Adds an `at_exit` hook to flush the async message queue when using the library in async mode.
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stenotype (0.1.3)
4
+ stenotype (0.1.9)
5
5
  activesupport (>= 5.0.0)
6
6
  google-cloud-pubsub (~> 1.0.0)
7
- spicery (>= 0.19.0, < 1.0)
7
+ spicery (>= 0.22.0, < 1.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -53,37 +53,43 @@ GEM
53
53
  addressable (2.7.0)
54
54
  public_suffix (>= 2.0.2, < 5.0)
55
55
  arel (9.0.0)
56
- around_the_world (0.19.2)
56
+ around_the_world (0.22.2)
57
57
  activesupport (>= 5.2.1)
58
58
  ast (2.4.0)
59
59
  builder (3.2.3)
60
60
  coderay (1.1.2)
61
- collectible (0.19.2)
61
+ collectible (0.22.2)
62
62
  activesupport (>= 5.2.1)
63
- short_circu_it (= 0.19.2)
64
- tablesalt (= 0.19.2)
63
+ short_circu_it (= 0.22.2)
64
+ tablesalt (= 0.22.2)
65
65
  concurrent-ruby (1.1.5)
66
- conjunction (0.19.2)
66
+ conjunction (0.22.2)
67
+ activemodel (>= 5.2.1)
67
68
  activesupport (>= 5.2.1)
69
+ spicerack (= 0.22.2)
68
70
  crass (1.0.5)
69
71
  diff-lcs (1.3)
72
+ directive (0.22.2)
73
+ activesupport (>= 5.2.1)
70
74
  docile (1.3.2)
71
75
  erubi (1.9.0)
72
- facet (0.19.2)
76
+ facet (0.22.2)
73
77
  activesupport (>= 5.2.1)
74
- short_circu_it (= 0.19.2)
75
- tablesalt (= 0.19.2)
78
+ short_circu_it (= 0.22.2)
79
+ tablesalt (= 0.22.2)
76
80
  faker (1.9.6)
77
81
  i18n (>= 0.7)
78
- faraday (0.17.1)
82
+ faraday (0.17.3)
79
83
  multipart-post (>= 1.2, < 3)
80
84
  github-markup (3.0.4)
81
85
  globalid (0.4.2)
82
86
  activesupport (>= 4.2.0)
83
- google-cloud-core (1.4.1)
87
+ google-cloud-core (1.5.0)
84
88
  google-cloud-env (~> 1.0)
89
+ google-cloud-errors (~> 1.0)
85
90
  google-cloud-env (1.3.0)
86
91
  faraday (~> 0.11)
92
+ google-cloud-errors (1.0.0)
87
93
  google-cloud-pubsub (1.0.2)
88
94
  concurrent-ruby (~> 1.1)
89
95
  google-cloud-core (~> 1.2)
@@ -96,7 +102,7 @@ GEM
96
102
  googleauth (~> 0.9)
97
103
  grpc (~> 1.24)
98
104
  rly (~> 0.2.3)
99
- google-protobuf (3.11.1)
105
+ google-protobuf (3.11.2)
100
106
  googleapis-common-protos (1.3.9)
101
107
  google-protobuf (~> 3.0)
102
108
  googleapis-common-protos-types (~> 1.0)
@@ -110,7 +116,7 @@ GEM
110
116
  multi_json (~> 1.11)
111
117
  os (>= 0.9, < 2.0)
112
118
  signet (~> 0.12)
113
- grpc (1.25.0)
119
+ grpc (1.26.0)
114
120
  google-protobuf (~> 3.8)
115
121
  googleapis-common-protos-types (~> 1.0)
116
122
  grpc-google-iam-v1 (0.6.9)
@@ -146,7 +152,7 @@ GEM
146
152
  pry (0.12.2)
147
153
  coderay (~> 1.1.0)
148
154
  method_source (~> 0.9.0)
149
- public_suffix (4.0.1)
155
+ public_suffix (4.0.3)
150
156
  rack (2.0.8)
151
157
  rack-test (1.1.0)
152
158
  rack (>= 1.0, < 3)
@@ -178,10 +184,10 @@ GEM
178
184
  rake (10.5.0)
179
185
  redcarpet (3.5.0)
180
186
  redis (4.1.3)
181
- redis_hash (0.19.2)
187
+ redis_hash (0.22.2)
182
188
  activesupport (>= 5.2.1)
183
189
  redis (>= 3.0)
184
- tablesalt (= 0.19.2)
190
+ tablesalt (= 0.22.2)
185
191
  rly (0.2.3)
186
192
  rspec (3.9.0)
187
193
  rspec-core (~> 3.9.0)
@@ -214,9 +220,9 @@ GEM
214
220
  rubocop-rspec (1.35.0)
215
221
  rubocop (>= 0.60.0)
216
222
  ruby-progressbar (1.10.1)
217
- short_circu_it (0.19.2)
223
+ short_circu_it (0.22.2)
218
224
  activesupport (>= 5.2.1)
219
- around_the_world (= 0.19.2)
225
+ around_the_world (= 0.22.2)
220
226
  signet (0.12.0)
221
227
  addressable (~> 2.3)
222
228
  faraday (~> 0.9)
@@ -227,22 +233,23 @@ GEM
227
233
  json (>= 1.8, < 3)
228
234
  simplecov-html (~> 0.10.0)
229
235
  simplecov-html (0.10.2)
230
- spicerack (0.19.2)
231
- around_the_world (= 0.19.2)
232
- redis_hash (= 0.19.2)
233
- short_circu_it (= 0.19.2)
234
- tablesalt (= 0.19.2)
235
- technologic (= 0.19.2)
236
+ spicerack (0.22.2)
237
+ around_the_world (= 0.22.2)
238
+ directive (= 0.22.2)
239
+ redis_hash (= 0.22.2)
240
+ short_circu_it (= 0.22.2)
241
+ tablesalt (= 0.22.2)
242
+ technologic (= 0.22.2)
236
243
  spicerack-styleguide (0.19.2)
237
244
  rubocop (= 0.74)
238
245
  rubocop-performance (= 1.4.1)
239
246
  rubocop-rails (= 2.3.0)
240
247
  rubocop-rspec (= 1.35.0)
241
- spicery (0.19.2)
242
- collectible (= 0.19.2)
243
- conjunction (= 0.19.2)
244
- facet (= 0.19.2)
245
- spicerack (= 0.19.2)
248
+ spicery (0.22.2)
249
+ collectible (= 0.22.2)
250
+ conjunction (= 0.22.2)
251
+ facet (= 0.22.2)
252
+ spicerack (= 0.22.2)
246
253
  sprockets (4.0.0)
247
254
  concurrent-ruby (~> 1.0)
248
255
  rack (> 1, < 3)
@@ -250,13 +257,13 @@ GEM
250
257
  actionpack (>= 4.0)
251
258
  activesupport (>= 4.0)
252
259
  sprockets (>= 3.0.0)
253
- tablesalt (0.19.2)
260
+ tablesalt (0.22.2)
254
261
  activemodel (>= 5.2.1)
255
262
  activesupport (>= 5.2.1)
256
- technologic (0.19.2)
263
+ technologic (0.22.2)
257
264
  activesupport (>= 5.2.1)
258
265
  railties (>= 5.2.1)
259
- short_circu_it (= 0.19.2)
266
+ short_circu_it (= 0.22.2)
260
267
  thor (0.20.3)
261
268
  thread_safe (0.3.6)
262
269
  timecop (0.9.1)
data/README.md CHANGED
@@ -31,10 +31,11 @@ Stenotype.configure do |config|
31
31
  Stenotype::Adapters::GoogleCloud.new
32
32
  ]
33
33
 
34
- config.uuid_generator = SecureRandom
35
- config.dispatcher = Stenotype::Dispatcher.new
36
- config.logger = Logger.new(STDOUT)
37
- config.graceful_error_handling = true
34
+ config.uuid_generator = SecureRandom
35
+ config.dispatcher = Stenotype::Dispatcher.new
36
+ config.logger = Logger.new(STDOUT)
37
+ config.graceful_error_handling = true
38
+ config.auto_adapter_initialization = true
38
39
 
39
40
  config.google_cloud do |gc_config|
40
41
  gc_config.project_id = "google_cloud_project_id"
@@ -98,6 +99,10 @@ Allows to enable/disable Rails ActionController extension
98
99
 
99
100
  Allows to enable/disable Rails ActiveJob extension
100
101
 
102
+ #### config.rails.auto_adapter_initialization
103
+
104
+ Controls whether the hook `auto_initialize!` is run for each adapter. If set to true `auto_initialize!` is invoked for every adapter. If false `auto_initialize!` is not run. For example for google cloud adapter this will instantiate `client` and `topic` objects before first publish. If set to false `client` and `topic` are lazy initialized.
105
+
101
106
  #### Configuring context handlers
102
107
 
103
108
  Each event is emitted in a context which might be an ActionController instance or an ActiveJob instance or potentially any other place. Context handlers are implemented as plain ruby classes, so before using them you must register them. By default a plain `Class` handler is registered when not used with any framework. In case Ruby on Rails is used, then there are two additional context handlers for `ActionController` and `ActiveJob` instances.
@@ -228,6 +233,14 @@ class CustomAdapter < Stenotype::Adapters::Base
228
233
  def publish(event_data, **additional_arguments)
229
234
  # custom publishing logic
230
235
  end
236
+
237
+ def flush!
238
+ # actions to be taken to flush the messages
239
+ end
240
+
241
+ def auto_initialize!
242
+ # actions to be taken to setup internal adapter state (client, endpoint, whatsoever)
243
+ end
231
244
  end
232
245
  ```
233
246
 
data/lib/stenotype.rb CHANGED
@@ -28,7 +28,7 @@ module Stenotype
28
28
  # has never been registered in known handlers in {Stenotype::ContextHandlers::Collection}.
29
29
  class UnknownHandlerError < Error; end
30
30
 
31
- include Spicerack::Configurable::ConfigDelegation
31
+ include Directive::ConfigDelegation
32
32
  delegates_to_configuration
33
33
  end
34
34
 
@@ -42,6 +42,14 @@ module Stenotype
42
42
  "#{self.class.name} must implement method #publish"
43
43
  end
44
44
 
45
+ #
46
+ # Allows custom setup of the adapter. Noop by default
47
+ # @abstract
48
+ #
49
+ def auto_initialize!
50
+ # noop by default
51
+ end
52
+
45
53
  #
46
54
  # This method is expected to be implemented by subclasses. In case async
47
55
  # publisher is used the process might end before the async queue of
@@ -35,7 +35,7 @@ module Stenotype
35
35
  #
36
36
  class GoogleCloud < Base
37
37
  #
38
- # @param event_data {Hash} The data to be published to Google Cloud
38
+ # @param event_data {String} The data to be published to Google Cloud
39
39
  # @raise {Stenotype::MessageNotPublishedError} unless message is published
40
40
  #
41
41
  # @example With default client
@@ -66,6 +66,16 @@ module Stenotype
66
66
  topic.async_publisher.stop.wait!
67
67
  end
68
68
 
69
+ #
70
+ # If not called both client and topic are lazy initialized on first call (if not
71
+ # passed to #initialize). #auto_initialize! is going to explicitly initialize
72
+ # both client and topic.
73
+ #
74
+ def auto_initialize!
75
+ client
76
+ topic
77
+ end
78
+
69
79
  private
70
80
 
71
81
  def publish_sync(event_data, **additional_attrs)
@@ -21,7 +21,7 @@ module Stenotype
21
21
  #
22
22
  class StdoutAdapter < Base
23
23
  #
24
- # @param event_data {Hash} The data to be published to STDOUT
24
+ # @param event_data {Sting} The data to be published to STDOUT
25
25
  #
26
26
  # @example Publishing to default client (STDOUT)
27
27
  # adapter = Stenotype::Adapters::StdoutAdapter.new
@@ -33,10 +33,7 @@ module Stenotype
33
33
  #
34
34
  def publish(event_data, **additional_attrs)
35
35
  client.info("[Stenotype::Event] emitted with the following attributes") do
36
- {
37
- **event_data,
38
- **additional_attrs,
39
- }
36
+ "MESSAGE BODY: #{event_data}, MESSAGE ATTRIBUTES #{additional_attrs.to_json}"
40
37
  end
41
38
  end
42
39
 
@@ -1,8 +1,10 @@
1
- require 'stenotype'
1
+ # frozen_string_literal: true
2
2
 
3
3
  # :nocov:
4
+ require "stenotype"
5
+
4
6
  at_exit do
5
7
  targets = Stenotype.config.targets
6
8
  targets.each(&:flush!)
7
9
  end
8
- # :nocov:
10
+ # :nocov:
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "directive"
4
+
3
5
  module Stenotype
4
6
  #
5
7
  # A module containing freshly-event gem configuration
@@ -24,7 +26,7 @@ module Stenotype
24
26
  # end
25
27
  #
26
28
  module Configuration
27
- extend Spicerack::Configurable
29
+ extend Directive
28
30
 
29
31
  # @!attribute graceful_error_handling
30
32
  # @return {true, false} a flag for suppressing error raised withing the gem
@@ -35,6 +37,9 @@ module Stenotype
35
37
  # @!attribute enabled
36
38
  # @return {true, false} a flag indicating whether event emission is enabled
37
39
 
40
+ # @!attribute auto_adapter_initialization
41
+ # @return {true, false} enables/disables lazy initialization of adapters' clients
42
+
38
43
  # @!attribute targets
39
44
  # @return {Array<#publish>} a list of targets responding to method [#publish]
40
45
 
@@ -59,7 +64,6 @@ module Stenotype
59
64
  # @!attribute [rw] google_cloud.async
60
65
  # @return [true, false] GC publish mode, either async if true, sync if false
61
66
 
62
-
63
67
  # @!attribute [rw] rails
64
68
  # @return [NestedConfiguration] Rails configuration.
65
69
 
@@ -87,6 +91,7 @@ module Stenotype
87
91
  nested :rails do
88
92
  option :enable_action_controller_ext, default: true
89
93
  option :enable_active_job_ext, default: true
94
+ option :auto_adapter_initialization, default: false
90
95
  end
91
96
  end
92
97
 
@@ -110,6 +115,7 @@ module Stenotype
110
115
  #
111
116
  def logger
112
117
  return config.logger if config.logger
118
+
113
119
  config.logger || Logger.new(STDOUT)
114
120
  end
115
121
 
@@ -21,7 +21,7 @@ module Stenotype
21
21
  event_data = serializer.new(event).serialize
22
22
 
23
23
  targets.each do |t|
24
- t.publish(event_data)
24
+ t.publish(event_data.to_json)
25
25
  end
26
26
 
27
27
  self
@@ -24,12 +24,12 @@ module Stenotype
24
24
  event = new(name, attributes, eval_context: eval_context, dispatcher: dispatcher)
25
25
  event.emit!
26
26
  event
27
- rescue => error
27
+ rescue StandardError => exception
28
28
  #
29
29
  # @todo This is a temporary solution to enable conditional logger fetching
30
30
  # needs a fix to use default Spicerack::Configuration functionality
31
31
  #
32
- Stenotype::Configuration.logger.error(error)
32
+ Stenotype::Configuration.logger.error(exception)
33
33
 
34
34
  raise Stenotype::Error unless Stenotype.config.graceful_error_handling
35
35
  end
@@ -68,12 +68,12 @@ module Stenotype
68
68
 
69
69
  begin
70
70
  dispatcher.publish(self)
71
- rescue => error
71
+ rescue StandardError => exception
72
72
  #
73
73
  # @todo This is a temporary solution to enable conditional logger fetching
74
74
  # needs a fix to use default Spicerack::Configuration functionality
75
75
  #
76
- Stenotype::Configuration.logger.error(error)
76
+ Stenotype::Configuration.logger.error(exception)
77
77
 
78
78
  raise Stenotype::Error unless Stenotype.config.graceful_error_handling
79
79
  end
@@ -18,6 +18,8 @@ module Stenotype
18
18
 
19
19
  config.stenotype = Stenotype.config
20
20
 
21
+ config.after_initialize { config.stenotype.targets.each(&:auto_initialize!) } if config.stenotype.rails.auto_adapter_initialization
22
+
21
23
  if config.stenotype.rails.enable_action_controller_ext
22
24
  ActiveSupport.on_load(:action_controller) do
23
25
  Stenotype::ContextHandlers.register Stenotype::ContextHandlers::Rails::Controller
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Stenotype
4
4
  # :nodoc:
5
- VERSION = "0.1.5"
5
+ VERSION = "0.1.10"
6
6
  # :nodoc:
7
7
  end
data/stenotype.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "activesupport", ">= 5.0.0"
33
33
  spec.add_dependency "google-cloud-pubsub", "~> 1.0.0"
34
34
 
35
- spec.add_runtime_dependency "spicery", ">= 0.19.0", "< 1.0"
35
+ spec.add_runtime_dependency "spicery", ">= 0.22.0", "< 1.0"
36
36
 
37
37
  spec.add_development_dependency "bundler", "~> 2.0"
38
38
  spec.add_development_dependency "github-markup", "~> 3.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stenotype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Kapitonov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-13 00:00:00.000000000 Z
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,7 +44,7 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.19.0
47
+ version: 0.22.0
48
48
  - - "<"
49
49
  - !ruby/object:Gem::Version
50
50
  version: '1.0'
@@ -54,7 +54,7 @@ dependencies:
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: 0.19.0
57
+ version: 0.22.0
58
58
  - - "<"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.0'
@@ -245,6 +245,7 @@ executables: []
245
245
  extensions: []
246
246
  extra_rdoc_files: []
247
247
  files:
248
+ - ".github/workflows/rspec.yml"
248
249
  - ".gitignore"
249
250
  - ".rspec"
250
251
  - ".rubocop.yml"