grape_rails_logger 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/grape_rails_logger/subscriber.rb +39 -7
- data/lib/grape_rails_logger/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e4483b69705ac60afc5e74a55a4b1d865ba08c6569e449cb2e7fcc9b82e8e449
|
|
4
|
+
data.tar.gz: d54444fd7424e615b480ca6bf85346eb3afef76d07f57991b5f342a8b7d79f39
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9c92013348863f50c25ed04f6c1c0141dc1b0b2fe6f73d4713cc2ba3ae0476beda731d5a8e0f9daa7fe7937f98fd07570483a3d9bdf1f30828b80c4a13496f7b
|
|
7
|
+
data.tar.gz: 4b95fcc595e37b91076965409651fc453cd112d16414c328ac20ab5daab090cade361f3836199ec351c9de1fddd091d4c05a7800dbde06f4ca26e1b79b2a378a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 1.2.2 (2026-09-15)
|
|
4
|
+
|
|
5
|
+
- Allow grape 4.x by expanding the runtime dependency to `< 5.0`
|
|
6
|
+
- Keep request log action names when grape stores path and method on endpoint config instead of `options`
|
|
7
|
+
|
|
3
8
|
## 1.2.1 (2026-07-18)
|
|
4
9
|
|
|
5
10
|
- Fix HTTP status in Grape request logs for exception subclasses of mapped error types
|
|
@@ -481,21 +481,52 @@ module GrapeRailsLogger
|
|
|
481
481
|
def extract_action(event)
|
|
482
482
|
endpoint = event.payload.dig(:env, "api.endpoint")
|
|
483
483
|
return "unknown" unless endpoint
|
|
484
|
-
return "unknown" unless endpoint.respond_to?(:options)
|
|
485
|
-
return "unknown" unless endpoint.options
|
|
486
484
|
|
|
487
|
-
method = endpoint
|
|
488
|
-
path = endpoint
|
|
485
|
+
method = first_list_item(endpoint_http_methods(endpoint))
|
|
486
|
+
path = first_list_item(endpoint_paths(endpoint))
|
|
489
487
|
return "unknown" unless method && path
|
|
490
488
|
|
|
491
|
-
|
|
489
|
+
method_name = method.to_s.downcase
|
|
490
|
+
return method_name if path == "/" || path.empty?
|
|
492
491
|
|
|
493
492
|
clean_path = path.to_s.delete_prefix("/").gsub(/[:\/]/, "_").squeeze("_").gsub(/^_+|_+$/, "")
|
|
494
|
-
"#{
|
|
493
|
+
"#{method_name}_#{clean_path}"
|
|
495
494
|
rescue
|
|
496
495
|
"unknown"
|
|
497
496
|
end
|
|
498
497
|
|
|
498
|
+
def endpoint_http_methods(endpoint)
|
|
499
|
+
config = endpoint_config(endpoint)
|
|
500
|
+
methods = config.http_methods if config.respond_to?(:http_methods)
|
|
501
|
+
return methods if methods
|
|
502
|
+
return nil unless endpoint.respond_to?(:options) && endpoint.options
|
|
503
|
+
|
|
504
|
+
endpoint.options[:method]
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
def endpoint_paths(endpoint)
|
|
508
|
+
config = endpoint_config(endpoint)
|
|
509
|
+
paths = config.path if config.respond_to?(:path)
|
|
510
|
+
return paths if paths
|
|
511
|
+
return nil unless endpoint.respond_to?(:options) && endpoint.options
|
|
512
|
+
|
|
513
|
+
endpoint.options[:path]
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
# grape 4 stores definition-time verbs and path on protected Endpoint#config
|
|
517
|
+
def endpoint_config(endpoint)
|
|
518
|
+
return unless endpoint.respond_to?(:config, true)
|
|
519
|
+
|
|
520
|
+
endpoint.send(:config)
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
def first_list_item(value)
|
|
524
|
+
return value if value.nil? || value.is_a?(String) || value.is_a?(Symbol)
|
|
525
|
+
return value.first if value.respond_to?(:first)
|
|
526
|
+
|
|
527
|
+
value
|
|
528
|
+
end
|
|
529
|
+
|
|
499
530
|
def extract_controller(event)
|
|
500
531
|
endpoint = event.payload.dig(:env, "api.endpoint")
|
|
501
532
|
return nil unless endpoint&.source&.source_location
|
|
@@ -678,7 +709,8 @@ module GrapeRailsLogger
|
|
|
678
709
|
endpoint = env["api.endpoint"]
|
|
679
710
|
return nil unless endpoint
|
|
680
711
|
|
|
681
|
-
api_class = endpoint.respond_to?(:
|
|
712
|
+
api_class = endpoint.respond_to?(:api) ? endpoint.api : nil
|
|
713
|
+
api_class ||= endpoint.respond_to?(:options) ? endpoint.options[:for] : nil
|
|
682
714
|
api_class ||= endpoint.respond_to?(:namespace) ? endpoint.namespace&.options&.dig(:for) : nil
|
|
683
715
|
api_class ||= endpoint.respond_to?(:route) ? endpoint.route&.options&.dig(:for) : nil
|
|
684
716
|
return nil unless api_class&.respond_to?(:content_types, true)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: grape_rails_logger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Makarov
|
|
@@ -58,7 +58,7 @@ dependencies:
|
|
|
58
58
|
version: '1.6'
|
|
59
59
|
- - "<"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '5.0'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -68,7 +68,7 @@ dependencies:
|
|
|
68
68
|
version: '1.6'
|
|
69
69
|
- - "<"
|
|
70
70
|
- !ruby/object:Gem::Version
|
|
71
|
-
version: '
|
|
71
|
+
version: '5.0'
|
|
72
72
|
- !ruby/object:Gem::Dependency
|
|
73
73
|
name: rspec
|
|
74
74
|
requirement: !ruby/object:Gem::Requirement
|