stenotype 0.1.2 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b998a75c7aef576ca3040ad7cd7a07082fddc9cd937b57e3d3e84d807124aba
4
- data.tar.gz: 29d5bc462c420c881eeeeca851146c74e8f6db1240de777d8e19ca0806274fdd
3
+ metadata.gz: 9da486b9bc096f52bf0b4f81526d5d4922e0fa10a05141e28f2f55154c41cf3b
4
+ data.tar.gz: 2ef09f562429fded9c425086714985ef61736e458c9b111aeeb124d9e276f6db
5
5
  SHA512:
6
- metadata.gz: 71094a00ecce450e4e2edbbda1327cf2f794c52d5d64bd304b67ec5f2498e49020c0ed4f2a07bc9425d5df8929ebe2d809447ea4b52baca0eb6569af27fcf22a
7
- data.tar.gz: 1874d642a66cc7a2771fd78e92a2dc3e7aaea9ea520055cc2b7abe5bb2f9bf51dce5989e1498352411d134a371ec8b546ded1e8cb8e3d75b7408eaa340d06cbd
6
+ metadata.gz: 8db324c94a6d1fdbf2d692df8ae87dca43ede513a1df59e3ba0db91eaa0b2dd4e44ac7f5e7a4c52893049ca1181da61b9a32cca69312693115cc788eb2230125
7
+ data.tar.gz: 45292456af9acee8382436aa02452512bd29f7f40c1033f0a548a6b01fe12a6a8d78dd42a20193755a904a1837bf7ecd4831676a7f42aa4cae7b6bab4af7c1f4
data/.gitignore CHANGED
@@ -11,3 +11,6 @@
11
11
  .rspec_status
12
12
  /.rakeTasks
13
13
  /.idea
14
+
15
+ # rbenv
16
+ .ruby-version
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
 
3
- *Release Date*: 2019/11/21
3
+ *Release Date*: 2020/01/10
4
+
5
+ ### 0.1.3: 2020/01/10
6
+ * Adds a new configuration option `graceful_error_handling` to suppress errors raised from the gem's internals yet logging the error to specified `config.logger`
7
+ * Adds a new configuration option `logger` to use during error handling
8
+ * Adds a new config option `Stenotype.config.enabled`. If the option is set to false then event is not going to be published. The option is `true` by default.
4
9
 
5
10
  ### 0.1.2: 2019/12/10
6
11
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stenotype (0.1.2)
4
+ stenotype (0.1.4)
5
5
  activesupport (>= 5.0.0)
6
6
  google-cloud-pubsub (~> 1.0.0)
7
7
  spicery (>= 0.19.0, < 1.0)
@@ -147,7 +147,7 @@ GEM
147
147
  coderay (~> 1.1.0)
148
148
  method_source (~> 0.9.0)
149
149
  public_suffix (4.0.1)
150
- rack (2.0.7)
150
+ rack (2.0.8)
151
151
  rack-test (1.1.0)
152
152
  rack (>= 1.0, < 3)
153
153
  rails (5.2.4)
data/README.md CHANGED
@@ -25,13 +25,16 @@ Or install it yourself as:
25
25
  Configuring the library is as simple as:
26
26
  ```ruby
27
27
  Stenotype.configure do |config|
28
+ config.enabled = true
28
29
  config.targets = [ # Supported targets
29
30
  Stenotype::Adapters::StdoutAdapter.new,
30
31
  Stenotype::Adapters::GoogleCloud.new
31
32
  ]
32
33
 
33
- config.uuid_generator = SecureRandom
34
- config.dispatcher = Stenotype::Dispatcher.new
34
+ config.uuid_generator = SecureRandom
35
+ config.dispatcher = Stenotype::Dispatcher.new
36
+ config.logger = Logger.new(STDOUT)
37
+ config.graceful_error_handling = true
35
38
 
36
39
  config.google_cloud do |gc_config|
37
40
  gc_config.project_id = "google_cloud_project_id"
@@ -47,10 +50,22 @@ Stenotype.configure do |config|
47
50
  end
48
51
  ```
49
52
 
53
+ #### config.enabled
54
+
55
+ A flag checked upon emission of an event. Will prevent event emission if set to false. An event is emitted if set to true.
56
+
50
57
  #### config.targets
51
58
 
52
59
  Contain an array of targets for the events to be published to. Targets must implement method `#publish(event_data, **additional_arguments)`.
53
60
 
61
+ #### config.logger
62
+
63
+ Specifies a logger for messages and exceptions to be output to. If not set defaults to `Logger.new(STDOUT)`, otherwise a manually set logger is used.
64
+
65
+ #### config.graceful_error_handling
66
+
67
+ This flag if set to `true` is going to suppress all `StandardError`'s raised within a gem. Raises the error to the caller if set to `false`
68
+
54
69
  #### config.uuid_generator
55
70
 
56
71
  An object that must implement method `#uuid`. Used when an event is emitted to generate a unique id for each event.
@@ -18,6 +18,9 @@ Rails.application.configure do
18
18
  # rails_modules.enable_active_job_ext = true
19
19
  # end
20
20
  #
21
+ # To enable or disable the library use the following config option:
22
+ #
23
+ # config.enabled = true # or false
21
24
  #
22
25
  # To make publishing possible one must specify a list of targets. You could use
23
26
  # StdoutAdapter for debug purposes before switching to a production publisher.
@@ -60,6 +63,14 @@ Rails.application.configure do
60
63
  #
61
64
  # config.dispatcher = Stenotype::Dispatcher
62
65
  #
66
+ # An option to suppress exception within a gem is available:
67
+ #
68
+ # config.graceful_error_handling = true
69
+ #
70
+ # To log errors a logger config option is available. Logger.new(STDOUT) is used by default.
71
+ #
72
+ # config.logger = Logger.new(STDOUT)
73
+ #
63
74
  # Add your own context handlers
64
75
  #
65
76
  # Stenotype::ContextHandlers.register Your::Custom::HandlerClass
@@ -6,6 +6,7 @@ module Stenotype
6
6
  #
7
7
  # @example Configuring the library
8
8
  # Stenotype.configure do |config|
9
+ # config.enabled = true
9
10
  # config.targets = [Target1.new, Target2.new]
10
11
  # config.uuid_generator = SecureRandom
11
12
  #
@@ -25,6 +26,15 @@ module Stenotype
25
26
  module Configuration
26
27
  extend Spicerack::Configurable
27
28
 
29
+ # @!attribute graceful_error_handling
30
+ # @return {true, false} a flag for suppressing error raised withing the gem
31
+
32
+ # @!attribute logger
33
+ # @return {Logger} a logger with default severity methods to output gem level messages
34
+
35
+ # @!attribute enabled
36
+ # @return {true, false} a flag indicating whether event emission is enabled
37
+
28
38
  # @!attribute targets
29
39
  # @return {Array<#publish>} a list of targets responding to method [#publish]
30
40
 
@@ -60,9 +70,12 @@ module Stenotype
60
70
  # @return [true, false] A flag of whether ActiveJob ext is enabled
61
71
 
62
72
  configuration_options do
73
+ option :graceful_error_handling, default: true
74
+ option :enabled, default: true
63
75
  option :targets, default: []
64
76
  option :dispatcher, default: Stenotype::Dispatcher
65
77
  option :uuid_generator, default: SecureRandom
78
+ option :logger
66
79
 
67
80
  nested :google_cloud do
68
81
  option :credentials, default: nil
@@ -79,6 +92,27 @@ module Stenotype
79
92
 
80
93
  module_function
81
94
 
95
+ #
96
+ # @example With default logger
97
+ # Stenotype.configure do |config|
98
+ # # config.logger = nil # logger not set manually
99
+ # end
100
+ # Stenotype.config.logger #=> `Logger.new(STDOUT)` instance
101
+ #
102
+ # @example With custom logger
103
+ # Stenotype.configure do |config|
104
+ # config.logger = custom_logger_instance
105
+ # end
106
+ # Stenotype.config.logger #=> custom_logger_instance
107
+ #
108
+ # @return [{Logger, CustomLogger}] a logger object. Logger.new(STDOUT) by
109
+ # default if another is not set during configuration
110
+ #
111
+ def logger
112
+ return config.logger if config.logger
113
+ config.logger || Logger.new(STDOUT)
114
+ end
115
+
82
116
  #
83
117
  # @example When at least one target is present
84
118
  # Stenotype.configure do |config|
@@ -93,6 +127,8 @@ module Stenotype
93
127
  # @raise {Stenotype::NoTargetsSpecifiedError} in case no targets are configured
94
128
  # @return {Array<#publish>} An array of targets implementing method [#publish]
95
129
  #
130
+ # @todo THIS NEVER GETS CALLED, needs a fix
131
+ #
96
132
  def targets
97
133
  return config.targets unless config.targets.empty?
98
134
 
@@ -18,9 +18,21 @@ module Stenotype
18
18
  # @return {Stenotype::Event} An instance of {Stenotype::Event}
19
19
  #
20
20
  def self.emit!(name, attributes = {}, eval_context: {}, dispatcher: Stenotype.config.dispatcher)
21
- event = new(name, attributes, eval_context: eval_context, dispatcher: dispatcher)
22
- event.emit!
23
- event
21
+ return unless Stenotype.config.enabled
22
+
23
+ begin
24
+ event = new(name, attributes, eval_context: eval_context, dispatcher: dispatcher)
25
+ event.emit!
26
+ event
27
+ rescue => error
28
+ #
29
+ # @todo This is a temporary solution to enable conditional logger fetching
30
+ # needs a fix to use default Spicerack::Configuration functionality
31
+ #
32
+ Stenotype::Configuration.logger.error(error)
33
+
34
+ raise unless Stenotype.config.graceful_error_handling
35
+ end
24
36
  end
25
37
 
26
38
  attr_reader :name, :attributes, :eval_context, :dispatcher
@@ -52,7 +64,19 @@ module Stenotype
52
64
  # event.emit! #=> Publishes the event to targets
53
65
  #
54
66
  def emit!
55
- dispatcher.publish(self)
67
+ return unless Stenotype.config.enabled
68
+
69
+ begin
70
+ dispatcher.publish(self)
71
+ rescue => error
72
+ #
73
+ # @todo This is a temporary solution to enable conditional logger fetching
74
+ # needs a fix to use default Spicerack::Configuration functionality
75
+ #
76
+ Stenotype::Configuration.logger.error(error)
77
+
78
+ raise unless Stenotype.config.graceful_error_handling
79
+ end
56
80
  end
57
81
  end
58
82
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Stenotype
4
4
  # :nodoc:
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.4"
6
6
  # :nodoc:
7
7
  end
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.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Kapitonov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-11 00:00:00.000000000 Z
11
+ date: 2020-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport