Class: ContextSpook::Generator
- Inherits:
-
Object
- Object
- ContextSpook::Generator
- Includes:
- VerbosePuts
- Defined in:
- lib/context_spook/generator.rb
Overview
The Generator class provides a DSL parser that interprets context definition files and constructs structured context objects containing project metadata, file contents, command outputs, and variables for AI assistance.
Defined Under Namespace
Classes: Context
Instance Method Summary collapse
-
#context(&block) ⇒ Context
The context method creates or returns a context object.
-
#initialize(verbose: false, &block) ⇒ Generator
constructor
The initialize method sets up the object by evaluating the provided block in the object’s context.
-
#output_context_size ⇒ Object
The output_context_size method prints the total size of the generated context JSON representation.
Methods included from VerbosePuts
Constructor Details
#initialize(verbose: false, &block) ⇒ Generator
The initialize method sets up the object by evaluating the provided block in the object’s context.
89 90 91 92 |
# File 'lib/context_spook/generator.rb', line 89 def initialize(verbose: false, &block) @verbose = !!verbose block and instance_eval(&block) end |
Instance Method Details
#context(&block) ⇒ Context
The context method creates or returns a context object.
99 100 101 102 103 104 105 106 |
# File 'lib/context_spook/generator.rb', line 99 def context(&block) if block @context and raise ArgumentError, "only one context allowed" @context = Context.new(verbose: @verbose, &block) else @context end end |
#output_context_size ⇒ Object
The output_context_size method prints the total size of the generated context JSON representation.
This method calculates the size of the context object when serialized to JSON, formats it using binary units (KiB, MiB, etc.), and outputs the result to standard error.
114 115 116 117 118 |
# File 'lib/context_spook/generator.rb', line 114 def output_context_size context_size = @context&.size.to_i json_context_size = ContextSpook::Utils.format_size(context_size) verbose_puts "Built #{json_context_size} of JSON context in total." end |