twiglet 3.12.0 → 3.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/twiglet/logger.rb +7 -0
- data/lib/twiglet/version.rb +1 -1
- data/test/logger_test.rb +61 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 286d683bc94e381966b7b0ee5c5ed2aec7e690e34e13136dadcd9f9903bc491c
|
4
|
+
data.tar.gz: be8be7205cb345e06da67d6bb4cd1bd6f23fb4f2c3d354ccbda6f6f4086710e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cdfb033d22ad7e0c8f588673c6ccc3dc47e75317c1f11b4e24be0d246f10323d064d18f7a5a7746e7e723365b894dfbdbee36a9d1410fef7321a794e7c3052c
|
7
|
+
data.tar.gz: 33872aecd0f6eafb9a117fa4a001ccaa1629ac18fa7c88ea109e4c5001df4f3ce324ece7e795c6e86428612edd6f57fee541b90801bd0ba185a9bd7cfb2c7785
|
data/lib/twiglet/logger.rb
CHANGED
@@ -81,6 +81,13 @@ module Twiglet
|
|
81
81
|
)
|
82
82
|
end
|
83
83
|
|
84
|
+
def validation_schema(validation_schema)
|
85
|
+
self.class.new(
|
86
|
+
@service_name,
|
87
|
+
**@args.merge(validation_schema: validation_schema)
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
84
91
|
def context_provider(&blk)
|
85
92
|
new_context_providers = Array(@args[:context_providers])
|
86
93
|
new_context_providers << blk
|
data/lib/twiglet/version.rb
CHANGED
data/test/logger_test.rb
CHANGED
@@ -681,11 +681,71 @@ describe Twiglet::Logger do
|
|
681
681
|
end
|
682
682
|
end
|
683
683
|
|
684
|
+
describe '#validation_schema' do
|
685
|
+
it 'allows for reconfiguring the validation_schema on new logger instances' do
|
686
|
+
validation_schema = <<-JSON
|
687
|
+
{
|
688
|
+
"type": "object",
|
689
|
+
"required": ["pet"],
|
690
|
+
"properties": {
|
691
|
+
"pet": {
|
692
|
+
"type": "object",
|
693
|
+
"required": ["name", "best_boy_or_girl?"],
|
694
|
+
"properties": {
|
695
|
+
"name": {
|
696
|
+
"type": "string",
|
697
|
+
"minLength": 1
|
698
|
+
},
|
699
|
+
"best_boy_or_girl?": {
|
700
|
+
"type": "boolean"
|
701
|
+
}
|
702
|
+
}
|
703
|
+
}
|
704
|
+
}
|
705
|
+
}
|
706
|
+
JSON
|
707
|
+
|
708
|
+
logger = Twiglet::Logger.new(
|
709
|
+
'petshop',
|
710
|
+
now: @now,
|
711
|
+
output: @buffer
|
712
|
+
)
|
713
|
+
|
714
|
+
message = { message: 'hi' }
|
715
|
+
|
716
|
+
pet_message = {
|
717
|
+
pet: { name: 'Davis', best_boy_or_girl?: true, species: 'dog' }
|
718
|
+
}
|
719
|
+
|
720
|
+
logger.info(message)
|
721
|
+
log = read_json(@buffer)
|
722
|
+
assert_equal 'hi', log[:message]
|
723
|
+
|
724
|
+
error = assert_raises JSON::Schema::ValidationError do
|
725
|
+
logger.info(pet_message)
|
726
|
+
end
|
727
|
+
assert_equal "The property '#/' did not contain a required property of 'message'", error.message
|
728
|
+
|
729
|
+
logger = logger.validation_schema(validation_schema)
|
730
|
+
|
731
|
+
error = assert_raises JSON::Schema::ValidationError do
|
732
|
+
logger.info(message)
|
733
|
+
end
|
734
|
+
assert_equal "The property '#/' did not contain a required property of 'pet'", error.message
|
735
|
+
|
736
|
+
logger.info(pet_message)
|
737
|
+
log = read_json(@buffer)
|
738
|
+
assert_equal 'Davis', log[:pet][:name]
|
739
|
+
end
|
740
|
+
end
|
741
|
+
|
684
742
|
private
|
685
743
|
|
686
744
|
def read_json(buffer)
|
687
745
|
buffer.rewind
|
688
|
-
|
746
|
+
string = buffer.read
|
747
|
+
buffer.rewind
|
748
|
+
JSON.parse(string, symbolize_names: true)
|
689
749
|
end
|
690
750
|
end
|
691
751
|
# rubocop:enable Metrics/BlockLength
|
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.
|
4
|
+
version: 3.13.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: 2024-08-
|
11
|
+
date: 2024-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|