module LittleGhost::Support
Support collects small building blocks for LittleGhost extensions. They are available to applications that need the same cancellation, loading, callback, execution, and diagnostic behavior as the framework.
Public Instance Methods
# File lib/little_ghost/support.rb, line 14 def deep_dup(value, ancestors = {}) if value.is_a?(Hash) || value.is_a?(Array) || value.is_a?(Data) identity = value.object_id raise ArgumentError, "cyclic values cannot be duplicated" if ancestors.key?(identity) ancestors[identity] = true end case value when Hash value.each_with_object({}) do |(key, child), copy| copy[deep_dup(key, ancestors)] = deep_dup(child, ancestors) end when Array value.map { |child| deep_dup(child, ancestors) } when String value.dup when Data value.class.new(**value.to_h.transform_values { |child| deep_dup(child, ancestors) }) else value end ensure ancestors.delete(identity) if identity end
Recursively duplicates hashes, arrays, and strings while preserving other values. Cyclic containers are not supported.
Source
# File lib/little_ghost/support.rb, line 44 def diagnostic_exception(error) { type: error.class.name, message: error.message, provider_response: diagnostic_provider_response(error), stacktrace: Array(error.backtrace).join("\n") }.compact end
Describes error for diagnostic content capture: its class, message, backtrace, and, when error or its cause is a Providers::HTTPError with a body, the bounded provider response. A JSON response is parsed so key-based redaction applies to its fields. The response can repeat request details, so pass this value only through a Support::ContentCapture policy.