Module: ContextSpook

Includes:
DSLKit::Interpreter
Defined in:
lib/context_spook/generator.rb,
lib/context_spook.rb,
lib/context_spook/version.rb

Overview

The ContextSpook module serves as a namespace container for collecting and organizing project information for AI assistance.

Defined Under Namespace

Modules: VerbosePuts Classes: Generator

Constant Summary collapse

VERSION =

ContextSpook version

'0.7.2'
VERSION_ARRAY =

:nodoc:

VERSION.split('.').map(&:to_i)
VERSION_MAJOR =

:nodoc:

VERSION_ARRAY[0]
VERSION_MINOR =

:nodoc:

VERSION_ARRAY[1]
VERSION_BUILD =

:nodoc:

VERSION_ARRAY[2]

Class Method Summary collapse

Class Method Details

.generate_context(filename = nil, verbose: false, &block) ⇒ ContextSpook::Generator::Context

The generate_context method processes a context definition file or block and returns the resulting context object.

This method serves as the primary entry point for generating project context data. It accepts either a filename pointing to a context definition file or a block containing the context definition, but not both. When a filename is provided, it reads and parses the file content. When a block is provided, it evaluates the block within the generator’s context. The method ensures that only one context definition mechanism is used.

Parameters:

  • filename (String, nil) (defaults to: nil)

    the path to the context definition file to be processed

  • verbose (TrueClass, FalseClass) (defaults to: false)

    flag to enable verbose output during processing, defaults to false.

  • block (Proc)

    a block containing the context definition to be evaluated

Returns:

Raises:

  • (ArgumentError)

    if neither a filename nor a block is provided

  • (ArgumentError)

    if both a filename and a block are provided



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/context_spook/generator.rb', line 59

def self.generate_context(filename = nil, verbose: false, &block)
  verbose = !!verbose
  filename.present? ^ block or
    raise ArgumentError, 'need either a filename or a &block argument'
  generator = if filename
                Generator.send(:new, verbose:).send(:parse, File.read(filename))
              else
                Generator.send(:new, verbose:, &block)
              end
  generator.output_context_size
  generator.context
end