Class: ContextSpook::Generator

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(&block) ⇒ Generator

The initialize method sets up the object by evaluating the provided block in the object’s context.



46
47
48
# File 'lib/context_spook/generator.rb', line 46

def initialize(&block)
  block and instance_eval(&block)
end

Instance Method Details

#context(&block) ⇒ Context

The context method creates or returns a context object.



55
56
57
58
59
60
61
62
# File 'lib/context_spook/generator.rb', line 55

def context(&block)
  if block
    @context and raise ArgumentError, "only one context allowed"
    @context = Context.new(&block)
  else
    @context
  end
end

#output_context_sizeObject

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.



70
71
72
73
74
75
76
# File 'lib/context_spook/generator.rb', line 70

def output_context_size
  context_size = @context&.size.to_i
  json_content_size = Tins::Unit.format(
    context_size, format: '%.2f %U', unit: ?b, prefix: 1024
  )
  STDERR.puts "Built #{json_content_size} of JSON context in total."
end