cogger 0.25.0 → 0.26.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: 82eadd70b70fc632efb641adf780c4f68fa76786ec1f170343e2e0dcb909182c
4
- data.tar.gz: 1b9f9159eb2e21950aec9a369a0272f68f4ae5111e104093ba491181f6c8edf3
3
+ metadata.gz: 8f0d785b86722f1a0d3247b5afc698df6f3cd643501ef2aa327cb2e45c23e77f
4
+ data.tar.gz: 510551f2a309c58768df7d207c73a0483c09c4cd6fb26454a4c05cfaf4826d35
5
5
  SHA512:
6
- metadata.gz: b7d78ff5e80252151ab31e919d46a56bce0fc64a118b3f6d961953bd8a4c8d53c2ecd2f670ccb058129a3f91817ed5ed45cead216461e1a66f6ece33210d10ad
7
- data.tar.gz: 45da02e73d70296f684f1de615f55a9ff37ca4df5ed0e31946af0951350a652f9936cd5d60032d0ab70dedd5093cd519f55feae961f830b9ef1dfbb31ff9603b
6
+ metadata.gz: 5603ca0a172662015262ca3d0a8702b8bff9cb16e07a85ad5f37040f9546a0e93a0e4b06ec350727224fe2dfa68471af20c47ac37487b124d393fdb8512ab7a2
7
+ data.tar.gz: 8184cd16ac184d2342d52a8b30a7ea98c0535eb9e749fcf3b60c32babbda0efb42c2b8dd324154819d41740d73a9c03e59b4e08bc7655c4709d17fd24186ecc5
checksums.yaml.gz.sig CHANGED
@@ -1,5 +1,2 @@
1
- X��u���F܉GJ�Xz��M�L��{~e�vQ@�OO���I 9Z���2ۼ�w�v��FI��R~pX{o���XϦp_R��4 �+� ,���mN����ټv맯
2
- ԪW��dy̆#�]R�]�b���%��s�ܒ�`�����H�%8Z����Y�Q�" �����Ak6v�c��m���b�$�]:n�1��LTՖcH�J�$m�����\�R��2-P1[fӜ
3
- ���pXAɖ4a�̙�b�t��>�=#m1�gq��Zg���9�"W��߇�z�$o$�"D
4
- �I�+�N��Z@&$
5
- ��9!Y,�X���{LVLC��8�o�Dl�R�BZu�4v)l2$��w]<���=A�0�������
1
+ ��6=�'���
2
+ ʅ�hMJg#��y㼑"Ed
data/cogger.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "cogger"
5
- spec.version = "0.25.0"
5
+ spec.version = "0.26.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/cogger"
data/lib/cogger/entry.rb CHANGED
@@ -15,10 +15,9 @@ module Cogger
15
15
  payload:
16
16
  end
17
17
 
18
- def self.for_crash message, error, id:, at: ::Time.now
18
+ def self.for_crash message, error, id:
19
19
  new id:,
20
20
  level: "FATAL",
21
- at:,
22
21
  message:,
23
22
  payload: {
24
23
  error_message: error.message,
@@ -4,10 +4,12 @@ module Cogger
4
4
  module Formatters
5
5
  # An abstract class with common/shared functionality.
6
6
  class Abstract
7
+ NEW_LINE = "\n"
8
+
7
9
  SANITIZERS = {
8
- datetime: Sanitizers::DateTime,
9
10
  escape: Sanitizers::Escape.new,
10
- filter: Sanitizers::Filter
11
+ filter: Sanitizers::Filter,
12
+ format_time: Sanitizers::FormatTime
11
13
  }.freeze
12
14
 
13
15
  def initialize sanitizers: SANITIZERS
@@ -23,10 +25,8 @@ module Cogger
23
25
 
24
26
  def sanitize entry, message
25
27
  entry.public_send(message).tap do |attributes|
26
- function = -> value { sanitize_datetime value, format: entry.datetime_format }
27
-
28
28
  filter attributes
29
- attributes.transform_values!(&function)
29
+ attributes.transform_values! { |value| format_time value, format: entry.datetime_format }
30
30
  end
31
31
  end
32
32
 
@@ -34,7 +34,7 @@ module Cogger
34
34
 
35
35
  def filter(...) = sanitizers.fetch(__method__).call(...)
36
36
 
37
- def sanitize_datetime(...) = sanitizers.fetch(:datetime).call(...)
37
+ def format_time(...) = sanitizers.fetch(__method__).call(...)
38
38
 
39
39
  private
40
40
 
@@ -16,7 +16,7 @@ module Cogger
16
16
  *, entry = input
17
17
  attributes = sanitize entry, :tagged
18
18
 
19
- "#{format(parse(attributes[:level]), attributes).tap(&:strip!)}\n"
19
+ format(parse(attributes[:level]), attributes).tap(&:strip!) << NEW_LINE
20
20
  end
21
21
 
22
22
  private
@@ -22,7 +22,7 @@ module Cogger
22
22
  attributes = sanitize entry, :tagged
23
23
  attributes[:backtrace] = %( #{attributes[:backtrace].join "\n "})
24
24
 
25
- "#{format(parse(attributes[:level]), attributes)}\n"
25
+ format(parse(attributes[:level]), attributes) << NEW_LINE
26
26
  end
27
27
 
28
28
  private
@@ -9,7 +9,7 @@ module Cogger
9
9
  class JSON < Abstract
10
10
  TEMPLATE = nil
11
11
 
12
- def initialize template = TEMPLATE, parser: Parsers::KeyExtractor.new
12
+ def initialize template = TEMPLATE, parser: Parsers::Position.new
13
13
  super()
14
14
  @template = template
15
15
  @parser = parser
@@ -19,22 +19,12 @@ module Cogger
19
19
  *, entry = input
20
20
  attributes = sanitize(entry, :tagged_attributes).tap(&:compact!)
21
21
 
22
- %(#{reorder(attributes).to_json}\n)
22
+ parser.call(template, attributes).to_json << NEW_LINE
23
23
  end
24
24
 
25
25
  private
26
26
 
27
27
  attr_reader :template, :parser
28
-
29
- def reorder attributes
30
- positions = positions_for template
31
-
32
- return attributes if positions.empty?
33
-
34
- attributes.slice(*positions).merge!(attributes.except(*positions))
35
- end
36
-
37
- def positions_for(template) = template ? parser.call(template) : Core::EMPTY_ARRAY
38
28
  end
39
29
  end
40
30
  end
@@ -10,9 +10,8 @@ module Cogger
10
10
  PATTERN = /
11
11
  % # Start.
12
12
  (?<flag>[\s#+-0*])? # Optional flag.
13
+ \.? # Optional precision.
13
14
  (?<width>\d+)? # Optional width.
14
- \.? # Optional precision delimiter.
15
- (?<precision>\d+)? # Optional precision value.
16
15
  < # Reference start.
17
16
  (?<key>\w+) # Key.
18
17
  : # Delimiter.
@@ -3,8 +3,8 @@
3
3
  module Cogger
4
4
  module Formatters
5
5
  module Parsers
6
- # Parses template and extracts keys.
7
- class KeyExtractor
6
+ # Parses template and reorders attributes based on template key positions.
7
+ class Position
8
8
  PATTERN = /
9
9
  % # Start.
10
10
  ? # Flag, width, or precision.
@@ -19,11 +19,20 @@ module Cogger
19
19
  @pattern = pattern
20
20
  end
21
21
 
22
- def call(template) = template.scan(pattern).map { |match| match.first.to_sym }
22
+ # :reek:FeatureEnvy
23
+ def call template, attributes
24
+ return attributes if !template || template.empty?
25
+ return attributes unless template.match? pattern
26
+
27
+ keys = scan template
28
+ attributes.slice(*keys).merge!(attributes.except(*keys))
29
+ end
23
30
 
24
31
  private
25
32
 
26
33
  attr_reader :pattern
34
+
35
+ def scan(template) = template.scan(pattern).map { |match| match.first.to_sym }
27
36
  end
28
37
  end
29
38
  end
@@ -8,7 +8,7 @@ module Cogger
8
8
  class Property < Abstract
9
9
  TEMPLATE = nil
10
10
 
11
- def initialize template = TEMPLATE, parser: Parsers::KeyExtractor.new
11
+ def initialize template = TEMPLATE, parser: Parsers::Position.new
12
12
  super()
13
13
  @template = template
14
14
  @parser = parser
@@ -18,7 +18,7 @@ module Cogger
18
18
  *, entry = input
19
19
  attributes = sanitize(entry, :tagged_attributes).tap(&:compact!)
20
20
 
21
- concat(attributes).chop! << "\n"
21
+ concat(attributes).chop! << NEW_LINE
22
22
  end
23
23
 
24
24
  private
@@ -26,20 +26,10 @@ module Cogger
26
26
  attr_reader :template, :parser
27
27
 
28
28
  def concat attributes
29
- reorder(attributes).each.with_object(+"") do |(key, value), line|
29
+ parser.call(template, attributes).each.with_object(+"") do |(key, value), line|
30
30
  line << key.to_s << "=" << escape(value) << " "
31
31
  end
32
32
  end
33
-
34
- def reorder attributes
35
- positions = positions_for template
36
-
37
- return attributes if positions.empty?
38
-
39
- attributes.slice(*positions).merge!(attributes.except(*positions))
40
- end
41
-
42
- def positions_for(template) = template ? parser.call(template) : Core::EMPTY_ARRAY
43
33
  end
44
34
  end
45
35
  end
@@ -6,7 +6,7 @@ module Cogger
6
6
  module Formatters
7
7
  module Sanitizers
8
8
  # Sanitizes/formats date/time value.
9
- DateTime = lambda do |value, format: Cogger::DATETIME_FORMAT|
9
+ FormatTime = lambda do |value, format: Cogger::DATETIME_FORMAT|
10
10
  return value unless value.is_a?(::Time) || value.is_a?(Date) || value.is_a?(::DateTime)
11
11
 
12
12
  value.strftime format
@@ -15,7 +15,7 @@ module Cogger
15
15
  *, entry = input
16
16
  attributes = sanitize entry, :tagged
17
17
 
18
- "#{format(template, attributes).tap(&:strip!)}\n"
18
+ format(template, attributes).tap(&:strip!) << NEW_LINE
19
19
  end
20
20
 
21
21
  private
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,7 +35,7 @@ cert_chain:
35
35
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
36
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
37
  -----END CERTIFICATE-----
38
- date: 2024-08-28 00:00:00.000000000 Z
38
+ date: 2024-08-30 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: core
@@ -118,11 +118,11 @@ files:
118
118
  - lib/cogger/formatters/parsers/element.rb
119
119
  - lib/cogger/formatters/parsers/emoji.rb
120
120
  - lib/cogger/formatters/parsers/key.rb
121
- - lib/cogger/formatters/parsers/key_extractor.rb
121
+ - lib/cogger/formatters/parsers/position.rb
122
122
  - lib/cogger/formatters/property.rb
123
- - lib/cogger/formatters/sanitizers/date_time.rb
124
123
  - lib/cogger/formatters/sanitizers/escape.rb
125
124
  - lib/cogger/formatters/sanitizers/filter.rb
125
+ - lib/cogger/formatters/sanitizers/format_time.rb
126
126
  - lib/cogger/formatters/simple.rb
127
127
  - lib/cogger/formatters/transformers/color.rb
128
128
  - lib/cogger/formatters/transformers/emoji.rb
metadata.gz.sig CHANGED
@@ -1 +1,4 @@
1
- !C��W��f��2=�us���d�1O<y��.���7%�4��Į"ыʳUC�yúf���k��k��Ia���j��}( 能�T˯~;�b.��=�l��5��Dz���l�Ou�%������b%
1
+ z�)��������I�z��� �zy=?�8p $%��� �z����c��S��q�@z����h�W�Uw�L��`�� �
2
+ �'Kul��E{���O���L�t��_[�[������[ 2n������$t�8Z��t�cc���{�)��B�g �5���<K��bS���])��c�_����^���'�7�3ƫ���7bN�p���<^�T=����
3
+ �p��e�7�A0��[���YM�N6pKjGO��6�Yb��,��4Iϛ��9D5�;63�ϡ��!tb?W�PH'�������'�A,��0�C�[.����S�4�)W?��\�Q֜ه+|/L�� g�P���:RoW45Un
4
+ Iet�l��DR���� H&��i