phobos 2.1.1 → 2.1.2

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: 6ec70d6f78852088846db2f5cee6673e9889962379bd82934758aa936886f1df
4
- data.tar.gz: f0d5a40fb1acbf02e0ac6cae4121571eb72689bc13076505153f33cef48f2362
3
+ metadata.gz: 687b8d954c8b21b656aaf41d7d4112d3e100d8845de0bd85436d38ebec4f6934
4
+ data.tar.gz: 8ed5b722c0b45e936092a6baab59302ba227fca3a243c24d97913050d3f18e71
5
5
  SHA512:
6
- metadata.gz: c7192c98b0e3f3b22ab3aa4ef4f28bf3227410120012d3b77a66f018960f0e72309f72d47a00e505355d906826dc89bdc327ceea50a99ea7e28d233602bd8ec6
7
- data.tar.gz: b1dab967fb374559b98d976b0628140692f9c080d3de55d17edaa2a885a4ef17a1bbf7555a380ef00199e62a002f0bdd6d56486e77fbe4f2176eb39756c4f185
6
+ metadata.gz: a12aa12ad91cdc2a681eea54c5a1db0f8d55cd16c79d7c02c0dc97f58152c1a7111e54455a66e8dda6eb38eee752894d2a74bad29f05b07b52fb9bf6ffda33f9
7
+ data.tar.gz: da1cb8365cb7504783db26b456de81611d69cd3c943840efef8af5a5688b301c8c736017b3991e6e8fd0feff290c33749d6d0b7ea37913093b28bc6aa7a964cf
data/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
  ``
7
7
  ## UNRELEASED
8
8
 
9
+ ## [2.1.2] - 2022-01-27
10
+
11
+ - Fix packaging error.
12
+
9
13
  ## [2.1.1] - 2022-01-26
10
14
 
11
15
  - Fix crash on Ruby 3.1 involving a change to the Psych gem.
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'phobos/deep_struct'
4
+
5
+ module Phobos
6
+ module Configuration
7
+ def configure(configuration)
8
+ @config = fetch_configuration(configuration)
9
+ @config.class.send(:define_method, :producer_hash) do
10
+ Phobos.config.producer&.to_hash&.except(:kafka)
11
+ end
12
+ @config.class.send(:define_method, :consumer_hash) do
13
+ Phobos.config.consumer&.to_hash&.except(:kafka)
14
+ end
15
+ @config.listeners ||= []
16
+ configure_logger
17
+ end
18
+
19
+ # :nodoc:
20
+ def configure_logger
21
+ Logging.backtrace(true)
22
+ Logging.logger.root.level = silence_log ? :fatal : config.logger.level
23
+
24
+ configure_ruby_kafka_logger
25
+ configure_phobos_logger
26
+
27
+ logger.info do
28
+ Hash(message: 'Phobos configured', env: ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'N/A')
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def fetch_configuration(configuration)
35
+ DeepStruct.new(read_configuration(configuration))
36
+ end
37
+
38
+ def read_configuration(configuration)
39
+ return configuration.to_h if configuration.respond_to?(:to_h)
40
+
41
+ config_erb = ERB.new(File.read(File.expand_path(configuration))).result
42
+
43
+ YAML.safe_load(
44
+ config_erb,
45
+ permitted_classes: [Symbol],
46
+ permitted_symbols: [],
47
+ aliases: true
48
+ )
49
+ rescue ArgumentError
50
+ YAML.safe_load(config_erb, [Symbol], [], true)
51
+ end
52
+
53
+ def configure_phobos_logger
54
+ if config.custom_logger
55
+ @logger = config.custom_logger
56
+ else
57
+ @logger = Logging.logger[self]
58
+ @logger.appenders = logger_appenders
59
+ end
60
+ end
61
+
62
+ def configure_ruby_kafka_logger
63
+ if config.custom_kafka_logger
64
+ @ruby_kafka_logger = config.custom_kafka_logger
65
+ elsif config.logger.ruby_kafka
66
+ @ruby_kafka_logger = Logging.logger['RubyKafka']
67
+ @ruby_kafka_logger.appenders = logger_appenders
68
+ @ruby_kafka_logger.level = silence_log ? :fatal : config.logger.ruby_kafka.level
69
+ else
70
+ @ruby_kafka_logger = nil
71
+ end
72
+ end
73
+
74
+ def logger_appenders
75
+ appenders = [Logging.appenders.stdout(layout: stdout_layout)]
76
+
77
+ if log_file
78
+ FileUtils.mkdir_p(File.dirname(log_file))
79
+ appenders << Logging.appenders.file(log_file, layout: json_layout)
80
+ end
81
+
82
+ appenders
83
+ end
84
+
85
+ def log_file
86
+ config.logger.file
87
+ end
88
+
89
+ def json_layout
90
+ Logging.layouts.json(date_pattern: Constants::LOG_DATE_PATTERN)
91
+ end
92
+
93
+ def stdout_layout
94
+ if config.logger.stdout_json == true
95
+ json_layout
96
+ else
97
+ Logging.layouts.pattern(date_pattern: Constants::LOG_DATE_PATTERN)
98
+ end
99
+ end
100
+ end
101
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phobos
4
- VERSION = '2.1.1'
4
+ VERSION = '2.1.2'
5
5
  end
data/lib/phobos.rb CHANGED
@@ -80,6 +80,5 @@ module Phobos
80
80
  location = caller.find { |line| line !~ %r{/phobos/} }
81
81
  warn "DEPRECATION WARNING: #{message}: #{location}"
82
82
  end
83
-
84
83
  end
85
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phobos
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Túlio Ornelas
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2022-01-26 00:00:00.000000000 Z
18
+ date: 2022-01-27 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler
@@ -277,6 +277,7 @@ files:
277
277
  - lib/phobos/cli.rb
278
278
  - lib/phobos/cli/runner.rb
279
279
  - lib/phobos/cli/start.rb
280
+ - lib/phobos/configuration.rb
280
281
  - lib/phobos/constants.rb
281
282
  - lib/phobos/deep_struct.rb
282
283
  - lib/phobos/echo_handler.rb
@@ -314,7 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
314
315
  - !ruby/object:Gem::Version
315
316
  version: '0'
316
317
  requirements: []
317
- rubygems_version: 3.3.3
318
+ rubygems_version: 3.2.22
318
319
  signing_key:
319
320
  specification_version: 4
320
321
  summary: Simplifying Kafka for ruby apps