umbrellio-utils 0.3.2 → 0.4.3

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: 2b63180fc355a29f6d9890b540e8fadfbc572070865b7309990de0bd0fc094ec
4
- data.tar.gz: 801fc30c7238f126b9fe705471be9d8d66f9b575e1789bd239d1868df323dfa8
3
+ metadata.gz: 6591e877185cd730c9c7fffd76144a0ab204fd8b3c69ea1765be7876209e715c
4
+ data.tar.gz: c08f9523f33faf6f6ea605edf44a9bb13a600e6fcfdf7620fadcde1f666dea78
5
5
  SHA512:
6
- metadata.gz: 1187dc1b14d139bb723e11be25e7a35412cc794618913272c10b9aeff8e5a98392525fc75bbfead6b6a59e7c8c37c305c7d27164eb2148da28540fad19ea1aac
7
- data.tar.gz: b4c696407bc41fb6ce2df840cb4476e99cdf68016e50a28545a33dcba615bc1dfd5b9c8822e5d357454207758538cd89b370b2efdf94ab950bfab74355ed5309
6
+ metadata.gz: b3c4ee473805b89b4b8f9e7c3de13c4ddbf5d7d3e22062c2e311149b5c2a9aa7d92d581523f5d586e015c0d4c54d3af0f8a89b2bfb84eeb24a26f0e6b97ffda8
7
+ data.tar.gz: e3aea7d7838ebd2ff3dd3b2d8fb7449563122349f099d469ea217e3fc4c8702b026c94e4240853f64fd402556a250e00a1fbc33b9ce3f46713565a55b3f7da9b
@@ -32,7 +32,6 @@ jobs:
32
32
  github-token: ${{ secrets.GITHUB_TOKEN }}
33
33
  specs:
34
34
  runs-on: ubuntu-latest
35
- continue-on-error: ${{ matrix.experimental }}
36
35
 
37
36
  env:
38
37
  FULL_TEST_COVERAGE_CHECK: false
@@ -44,10 +43,6 @@ jobs:
44
43
  fail-fast: false
45
44
  matrix:
46
45
  ruby: [2.6, 2.7]
47
- experimental: [false]
48
- include:
49
- - ruby: head
50
- experimental: true
51
46
 
52
47
 
53
48
  steps:
data/Gemfile.lock CHANGED
@@ -1,20 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- umbrellio-utils (0.3.2)
4
+ umbrellio-utils (0.4.3)
5
5
  memery (~> 1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (6.1.3.1)
10
+ activesupport (6.1.4.1)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
12
  i18n (>= 1.6, < 2)
13
13
  minitest (>= 5.1)
14
14
  tzinfo (~> 2.0)
15
15
  zeitwerk (~> 2.3)
16
16
  ast (2.4.2)
17
- bundler-audit (0.8.0)
17
+ awesome_print (1.9.2)
18
+ bundler-audit (0.9.0.1)
18
19
  bundler (>= 1.2.0, < 3)
19
20
  thor (~> 1.0)
20
21
  ci-helper (0.4.2)
@@ -23,31 +24,34 @@ GEM
23
24
  umbrellio-sequel-plugins (~> 0.4)
24
25
  coderay (1.1.3)
25
26
  colorize (0.8.1)
26
- concurrent-ruby (1.1.8)
27
+ concurrent-ruby (1.1.9)
27
28
  diff-lcs (1.4.4)
28
- docile (1.3.5)
29
- dry-inflector (0.2.0)
29
+ docile (1.4.0)
30
+ dry-inflector (0.2.1)
30
31
  i18n (1.8.10)
31
32
  concurrent-ruby (~> 1.0)
33
+ json (2.6.1)
32
34
  memery (1.4.1)
33
35
  ruby2_keywords (~> 0.0.2)
34
36
  method_source (1.0.0)
35
37
  minitest (5.14.4)
36
- nokogiri (1.12.2-x86_64-darwin)
38
+ nokogiri (1.12.5-arm64-darwin)
37
39
  racc (~> 1.4)
38
- nokogiri (1.12.2-x86_64-linux)
40
+ nokogiri (1.12.5-x86_64-darwin)
41
+ racc (~> 1.4)
42
+ nokogiri (1.12.5-x86_64-linux)
39
43
  racc (~> 1.4)
40
44
  nori (2.6.0)
41
- parallel (1.20.1)
42
- parser (3.0.1.0)
45
+ parallel (1.21.0)
46
+ parser (3.0.2.0)
43
47
  ast (~> 2.4.1)
44
- pry (0.14.0)
48
+ pry (0.14.1)
45
49
  coderay (~> 1.1)
46
50
  method_source (~> 1.0)
47
- racc (1.5.2)
51
+ racc (1.6.0)
48
52
  rack (2.2.3)
49
53
  rainbow (3.0.0)
50
- rake (13.0.3)
54
+ rake (13.0.6)
51
55
  regexp_parser (2.1.1)
52
56
  rexml (3.2.5)
53
57
  rspec (3.10.0)
@@ -59,23 +63,26 @@ GEM
59
63
  rspec-expectations (3.10.1)
60
64
  diff-lcs (>= 1.2.0, < 2.0)
61
65
  rspec-support (~> 3.10.0)
66
+ rspec-json_matcher (0.1.6)
67
+ awesome_print
68
+ json
62
69
  rspec-mocks (3.10.2)
63
70
  diff-lcs (>= 1.2.0, < 2.0)
64
71
  rspec-support (~> 3.10.0)
65
72
  rspec-support (3.10.2)
66
- rubocop (1.11.0)
73
+ rubocop (1.17.0)
67
74
  parallel (~> 1.10)
68
75
  parser (>= 3.0.0.0)
69
76
  rainbow (>= 2.2.2, < 4.0)
70
77
  regexp_parser (>= 1.8, < 3.0)
71
78
  rexml
72
- rubocop-ast (>= 1.2.0, < 2.0)
79
+ rubocop-ast (>= 1.7.0, < 2.0)
73
80
  ruby-progressbar (~> 1.7)
74
81
  unicode-display_width (>= 1.4.0, < 3.0)
75
- rubocop-ast (1.4.1)
76
- parser (>= 2.7.1.5)
77
- rubocop-config-umbrellio (1.11.0.40)
78
- rubocop (= 1.11.0)
82
+ rubocop-ast (1.12.0)
83
+ parser (>= 3.0.1.1)
84
+ rubocop-config-umbrellio (1.17.0.53)
85
+ rubocop (= 1.17.0)
79
86
  rubocop-performance (= 1.10.0)
80
87
  rubocop-rails (= 2.9.1)
81
88
  rubocop-rake (= 0.5.1)
@@ -97,26 +104,31 @@ GEM
97
104
  rubocop (~> 1.0)
98
105
  ruby-progressbar (1.11.0)
99
106
  ruby2_keywords (0.0.5)
100
- sequel (5.43.0)
107
+ semantic_logger (4.8.2)
108
+ concurrent-ruby (~> 1.0)
109
+ sequel (5.49.0)
101
110
  simplecov (0.21.2)
102
111
  docile (~> 1.1)
103
112
  simplecov-html (~> 0.11)
104
113
  simplecov_json_formatter (~> 0.1)
105
114
  simplecov-html (0.12.3)
106
115
  simplecov-lcov (0.8.0)
107
- simplecov_json_formatter (0.1.2)
108
- symbiont-ruby (0.6.0)
116
+ simplecov_json_formatter (0.1.3)
117
+ symbiont-ruby (0.7.0)
109
118
  thor (1.1.0)
119
+ timecop (0.9.4)
110
120
  tzinfo (2.0.4)
111
121
  concurrent-ruby (~> 1.0)
112
- umbrellio-sequel-plugins (0.4.0.164)
122
+ umbrellio-sequel-plugins (0.5.1.27)
113
123
  sequel
114
- symbiont-ruby (>= 0.6)
115
- unicode-display_width (2.0.0)
124
+ symbiont-ruby
125
+ unicode-display_width (2.1.0)
116
126
  yard (0.9.26)
117
- zeitwerk (2.4.2)
127
+ zeitwerk (2.5.1)
118
128
 
119
129
  PLATFORMS
130
+ arm64-darwin-20
131
+ arm64-darwin-21
120
132
  x86_64-darwin-20
121
133
  x86_64-linux
122
134
 
@@ -130,11 +142,14 @@ DEPENDENCIES
130
142
  pry
131
143
  rake
132
144
  rspec
145
+ rspec-json_matcher
133
146
  rubocop-config-umbrellio
147
+ semantic_logger
134
148
  simplecov
135
149
  simplecov-lcov
150
+ timecop
136
151
  umbrellio-utils!
137
152
  yard
138
153
 
139
154
  BUNDLED WITH
140
- 2.2.22
155
+ 2.3.0
@@ -67,7 +67,9 @@ module UmbrellioUtils
67
67
  type = model.db_schema[primary_key][:db_type]
68
68
 
69
69
  DB.drop_table?(temp_table_name)
70
- DB.create_table(temp_table_name) { column primary_key, type, primary_key: true }
70
+ DB.create_table(temp_table_name, unlogged: true) do
71
+ column primary_key, type, primary_key: true
72
+ end
71
73
 
72
74
  insert_ds = dataset.select(Sequel[model.table_name][primary_key])
73
75
  DB[temp_table_name].insert(insert_ds)
@@ -53,7 +53,7 @@ module UmbrellioUtils
53
53
  attr_accessor :request
54
54
 
55
55
  def parse_params
56
- case request.content_type
56
+ case request.media_type
57
57
  when "application/json"
58
58
  Parsing.safely_parse_json(body)
59
59
  when "application/xml"
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UmbrellioUtils
4
+ # Namespace for the differrent appenders and formatters for the SemanticLogger library.
5
+ # @see https://logger.rocketjob.io/ Semantic Logger documentation.
6
+ module SemanticLogger
7
+ # Simple JSON formatter, represented as callable object.
8
+ # @example Using of formatter
9
+ # formatter = UmbrellioUtils::SemanticLogger::TinyJsonFormatter.new
10
+ # SemanticLogger.add_appender(io: $stdout, formatter: formatter)
11
+ class TinyJsonFormatter
12
+ # Hash with default field names in the output JSON.
13
+ DEFAULT_NAMES_MAPPING = {
14
+ severity: :severity,
15
+ name: :name,
16
+ thread_fingerprint: :thread_fingerprint,
17
+ message: :message,
18
+ tags: :tags,
19
+ named_tags: :named_tags,
20
+ time: :time,
21
+ }.freeze
22
+
23
+ # Returns a new instance of the {UmbrellioUtils::SemanticLogger::TinyJsonFormatter}.
24
+ # @param [Hash] custom_names_mapping mapping from default field names to custom ones.
25
+ # @option custom_names_mapping [Symbol] :severity custom name for the `severity` field.
26
+ # @option custom_names_mapping [Symbol] :name custom name for the `name` field.
27
+ # @option custom_names_mapping [Symbol] :thread_fingerprint
28
+ # custom name for the thread_fingerprint field.
29
+ # @option custom_names_mapping [Symbol] :message custom name for the `message` field.
30
+ # @option custom_names_mapping [Symbol] :tags custom name for the `tags` field.
31
+ # @option custom_names_mapping [Symbol] :named_tags custom name for the `named_tags` field.
32
+ # @option custom_names_mapping [Symbol] :time custom name for the `time` field.
33
+ # @example Use custom name for the `message` and `time` fields
34
+ # UmbrellioUtils::SemanticLogger::TinyJsonFormatter.new(
35
+ # time: :timestamp, message: :note,
36
+ # ) #=> <UmbrellioUtils::SemanticLogger::TinyJsonFormatter:0x000>
37
+ # @return [UmbrellioUtils::SemanticLogger::TinyJsonFormatter]
38
+ # a new instance of the {UmbrellioUtils::SemanticLogger::TinyJsonFormatter}
39
+ def initialize(**custom_names_mapping)
40
+ self.field_names = { **DEFAULT_NAMES_MAPPING, **custom_names_mapping }.freeze
41
+ end
42
+
43
+ # Formats log structure into the JSON string.
44
+ # @param log [SemanticLogger::Log] log's data structure.
45
+ # @param logger [SemanticLogger::Logger] active logger.
46
+ # @return [String] data
47
+ def call(log, _logger)
48
+ data = build_data_for(log)
49
+ data.to_json
50
+ end
51
+
52
+ private
53
+
54
+ # @!attribute field_names
55
+ # @return [Hash<Symbol, Symbol>] the mapping from default field names to the new ones.
56
+ attr_accessor :field_names
57
+
58
+ # Builds hash with data from log.
59
+ # @return [Hash] the hash, which will be converted to the JSON later.
60
+ def build_data_for(log)
61
+ field_names.values_at(*DEFAULT_NAMES_MAPPING.keys).zip(pack_data(log)).to_h
62
+ end
63
+
64
+ # Builds an [Array] with all the required fields, which are arranged
65
+ # in the order of the declaration of keys
66
+ # in the {UmbrellioUtils::SemanticLogger::TinyJsonFormatter::DEFAULT_NAMES_MAPPING}.
67
+ # @return [Array] an array with serialized data.
68
+ def pack_data(log)
69
+ [
70
+ log.level.upcase,
71
+ log.name,
72
+ thread_fingerprint_for(log),
73
+ log.message,
74
+ log.tags,
75
+ log.named_tags,
76
+ log.time.utc.iso8601(3),
77
+ ]
78
+ end
79
+
80
+ # Calculates MD5 fingerprint for the thread, in which the log was made.
81
+ # @return [String] truncated `MD5` hash.
82
+ def thread_fingerprint_for(log)
83
+ Digest::MD5.hexdigest("#{log.thread_name}#{Process.pid}")[0...8]
84
+ end
85
+ end
86
+ end
87
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UmbrellioUtils
4
- VERSION = "0.3.2"
4
+ VERSION = "0.4.3"
5
5
  end
@@ -5,8 +5,6 @@ require "memery"
5
5
  module UmbrellioUtils
6
6
  GLOBAL_MUTEX = Mutex.new
7
7
 
8
- Dir["#{__dir__}/*/*.rb"].each { |file_path| require_relative(file_path) }
9
-
10
8
  extend self
11
9
 
12
10
  def included(othermod)
@@ -47,3 +45,21 @@ module UmbrellioUtils
47
45
  GLOBAL_MUTEX.owned? ? yield : GLOBAL_MUTEX.synchronize(&block)
48
46
  end
49
47
  end
48
+
49
+ require_relative "umbrellio_utils/cards"
50
+ require_relative "umbrellio_utils/checks"
51
+ require_relative "umbrellio_utils/constants"
52
+ require_relative "umbrellio_utils/control"
53
+ require_relative "umbrellio_utils/database"
54
+ require_relative "umbrellio_utils/formatting"
55
+ require_relative "umbrellio_utils/http_client"
56
+ require_relative "umbrellio_utils/misc"
57
+ require_relative "umbrellio_utils/parsing"
58
+ require_relative "umbrellio_utils/passwords"
59
+ require_relative "umbrellio_utils/random"
60
+ require_relative "umbrellio_utils/request_wrapper"
61
+ require_relative "umbrellio_utils/rounding"
62
+ require_relative "umbrellio_utils/semantic_logger/tiny_json_formatter"
63
+ require_relative "umbrellio_utils/store"
64
+ require_relative "umbrellio_utils/vault"
65
+ require_relative "umbrellio_utils/version"
@@ -38,8 +38,11 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency "pry"
39
39
  spec.add_development_dependency "rake"
40
40
  spec.add_development_dependency "rspec"
41
+ spec.add_development_dependency "rspec-json_matcher"
41
42
  spec.add_development_dependency "rubocop-config-umbrellio"
43
+ spec.add_development_dependency "semantic_logger"
42
44
  spec.add_development_dependency "simplecov"
43
45
  spec.add_development_dependency "simplecov-lcov"
46
+ spec.add_development_dependency "timecop"
44
47
  spec.add_development_dependency "yard"
45
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umbrellio-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - JustAnotherDude
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-09 00:00:00.000000000 Z
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: memery
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec-json_matcher
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop-config-umbrellio
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +178,20 @@ dependencies:
164
178
  - - ">="
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: semantic_logger
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
167
195
  - !ruby/object:Gem::Dependency
168
196
  name: simplecov
169
197
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +220,20 @@ dependencies:
192
220
  - - ">="
193
221
  - !ruby/object:Gem::Version
194
222
  version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: timecop
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
195
237
  - !ruby/object:Gem::Dependency
196
238
  name: yard
197
239
  requirement: !ruby/object:Gem::Requirement
@@ -240,6 +282,7 @@ files:
240
282
  - lib/umbrellio_utils/random.rb
241
283
  - lib/umbrellio_utils/request_wrapper.rb
242
284
  - lib/umbrellio_utils/rounding.rb
285
+ - lib/umbrellio_utils/semantic_logger/tiny_json_formatter.rb
243
286
  - lib/umbrellio_utils/store.rb
244
287
  - lib/umbrellio_utils/vault.rb
245
288
  - lib/umbrellio_utils/version.rb
@@ -266,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
309
  - !ruby/object:Gem::Version
267
310
  version: '0'
268
311
  requirements: []
269
- rubygems_version: 3.2.22
312
+ rubygems_version: 3.3.0
270
313
  signing_key:
271
314
  specification_version: 4
272
315
  summary: A set of utilities that speed up development