twiglet 3.9.2 → 3.10.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: 3b87b30fcde8a6363eb43ef4451718f3e15066a686b6ecd5340cb504cc3f0ebd
4
- data.tar.gz: 6efcea94e5b2623e3c01e974f34ad80f0c7238fb655f306415ad75a7105b0164
3
+ metadata.gz: 6362109470f346c6703ed9e13e82904195f201cac31e1edf1dad8714c4312d79
4
+ data.tar.gz: a06b359e837cf995f78efdab94c53e5017ccc4ca6d06373a05148f0e4b93621c
5
5
  SHA512:
6
- metadata.gz: 962d159d17c025956e0294d07ae9f452f10298c17fdaa3d56eb56e7547eee03ef324d260d58151553ada630eb2a5326650d22b6649ceb00ca8412dda7b27cb92
7
- data.tar.gz: e5a2394439c12bedc56de394e5275ae383c4c40debba8cdcd9a81aefe962afc9d81089df599ed6201103646136969356d7101bb570be8736987cfb3c150edb65
6
+ metadata.gz: cd56a05ee8a42910901a85de11940ea16b1e6a4578fd2501aeb4e794674561dd9594bb10fedc0b07c207df5823c44361cf1a72d753b241fe4e564e786464f459
7
+ data.tar.gz: 7fa75694d0ff55caa28df71703fd4e8c14e00185149c456b26c8030315519e0caafcc77e0e10efe1d04aae1093dd53c9f1b4462b97f04d8352c996241a271662
@@ -2,7 +2,7 @@
2
2
 
3
3
  module HashExtensions
4
4
  def to_nested
5
- self unless contains_dotted_key?
5
+ return self unless contains_dotted_key?
6
6
 
7
7
  keys.reduce({}) do |nested, key|
8
8
  nested.deep_merge(build_nested_object(key, self[key]))
@@ -82,9 +82,15 @@ module Twiglet
82
82
  end
83
83
 
84
84
  def context_provider(&blk)
85
+ new_context_provider = blk
86
+ if @args[:context_provider]
87
+ new_context_provider = lambda do
88
+ @args[:context_provider].call.merge(blk.call)
89
+ end
90
+ end
85
91
  self.class.new(
86
92
  @service_name,
87
- **@args.merge(context_provider: blk)
93
+ **@args.merge(context_provider: new_context_provider)
88
94
  )
89
95
  end
90
96
 
@@ -8,7 +8,7 @@ module Twiglet
8
8
  when Hash
9
9
  replace(msg.transform_keys!(&:to_sym))
10
10
  else
11
- super(msg)
11
+ super
12
12
  end
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twiglet
4
- VERSION = '3.9.2'
4
+ VERSION = '3.10.0'
5
5
  end
data/test/logger_test.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'minitest/autorun'
4
4
  require 'minitest/mock'
5
5
  require_relative '../lib/twiglet/logger'
6
+ require 'active_support'
6
7
 
7
8
  LEVELS = [
8
9
  { method: :debug, level: 'debug' },
@@ -266,6 +267,27 @@ describe Twiglet::Logger do
266
267
  assert_equal 'my-context-id', log[:context][:id]
267
268
  end
268
269
 
270
+ it "previously supplied context providers should be preserved" do
271
+ # Let's add some context to this customer journey
272
+ purchase_logger = @logger
273
+ .context_provider { { 'first-context' => { 'first-id' => 'my-first-context-id' } } }
274
+ .context_provider { { 'second-context' => { 'second-id' => 'my-second-context-id' } } }
275
+ # do stuff
276
+ purchase_logger.info(
277
+ {
278
+ message: 'customer bought a dog',
279
+ pet: { name: 'Barker', species: 'dog', breed: 'Bitsa' }
280
+ }
281
+ )
282
+
283
+ log = read_json @buffer
284
+
285
+ assert_equal 'customer bought a dog', log[:message]
286
+ assert_equal 'Barker', log[:pet][:name]
287
+ assert_equal 'my-first-context-id', log[:'first-context'][:'first-id']
288
+ assert_equal 'my-second-context-id', log[:'second-context'][:'second-id']
289
+ end
290
+
269
291
  it "should log 'message' string property" do
270
292
  message = {}
271
293
  message['message'] = 'Guinea pigs arrived'
@@ -393,8 +415,7 @@ describe Twiglet::Logger do
393
415
  assert_equal 'Some error', actual_log[:message]
394
416
  end
395
417
 
396
- it 'should log error type properly even when active_support/json is required' do
397
- require 'active_support/json'
418
+ it 'should log error type properly even when active_support is required' do
398
419
  e = StandardError.new('Unknown error')
399
420
  @logger.error('Artificially raised exception with string message', e)
400
421
 
data/twiglet.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.license = 'Copyright SimplyBusiness'
23
23
 
24
- gem.add_runtime_dependency 'json-schema'
24
+ gem.add_dependency 'json-schema'
25
25
  gem.add_development_dependency 'minitest'
26
26
  gem.add_development_dependency 'rake'
27
27
  gem.add_development_dependency 'simplecov', '0.17.1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twiglet
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.2
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simply Business
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-27 00:00:00.000000000 Z
11
+ date: 2024-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema