Class: Inquirex::CompletionMetadata
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Inquirex::CompletionMetadata
- Defined in:
- lib/inquirex/completion_metadata.rb
Overview
An OpenStruct describing how a flow reached completion: which rendering engine collected the answers, and any environment details that renderer chose to attach (host uname, user, IP addresses, terminal, ...).
Only :engine and :engine_version are required members — enforced at construction. Everything else is free-form OpenStruct behavior: unset members read as nil, assignment creates members, nested OpenStructs (e.g. uname) are welcome.
Constant Summary collapse
- REQUIRED_MEMBERS =
Members that must be provided at construction; everything else is optional.
%i[engine engine_version].freeze
Class Method Summary collapse
-
.from_h(hash) ⇒ CompletionMetadata?
Rebuilds an instance from a hash (e.g. persisted engine state after a JSON round-trip).
Instance Method Summary collapse
-
#initialize(engine:, engine_version:, **extra) ⇒ CompletionMetadata
constructor
Exists solely to make :engine and :engine_version required keywords — OpenStruct itself would accept anything.
-
#inspect ⇒ String
Debug representation of the deep-plain member hash.
-
#to_h ⇒ Hash
OpenStruct#to_h is shallow; deep-convert nested OpenStructs (uname et al.) so state serialization and JSON output stay plain data.
-
#to_json ⇒ String
JSON representation.
Constructor Details
#initialize(engine:, engine_version:, **extra) ⇒ CompletionMetadata
Exists solely to make :engine and :engine_version required keywords — OpenStruct itself would accept anything.
35 36 37 |
# File 'lib/inquirex/completion_metadata.rb', line 35 def initialize(engine:, engine_version:, **extra) # rubocop:disable Lint/UselessMethodDefinition super end |
Class Method Details
.from_h(hash) ⇒ CompletionMetadata?
Rebuilds an instance from a hash (e.g. persisted engine state after a JSON round-trip). Keys may be strings or symbols; nested hashes come back as OpenStructs so dot-access survives the round-trip.
46 47 48 49 50 51 |
# File 'lib/inquirex/completion_metadata.rb', line 46 def self.from_h(hash) return nil if hash.nil? || hash.empty? members = hash.to_h { |k, v| [k.to_sym, v.is_a?(Hash) ? OpenStruct.new(v) : v] } new(**members) end |
Instance Method Details
#inspect ⇒ String
Returns debug representation of the deep-plain member hash.
67 68 69 |
# File 'lib/inquirex/completion_metadata.rb', line 67 def inspect "#<Inquirex::CompletionMetadata #{to_h.inspect}>" end |
#to_h ⇒ Hash
OpenStruct#to_h is shallow; deep-convert nested OpenStructs (uname et al.) so state serialization and JSON output stay plain data.
57 58 59 |
# File 'lib/inquirex/completion_metadata.rb', line 57 def to_h deep_plain(super) end |
#to_json ⇒ String
Returns JSON representation.
62 63 64 |
# File 'lib/inquirex/completion_metadata.rb', line 62 def to_json(*) JSON.generate(to_h) end |