Module: ContextSpook

Includes:
DSLKit::Interpreter
Defined in:
lib/context_spook/generator.rb,
lib/context_spook.rb,
lib/context_spook/verbose_puts.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: OutputContext, TOON, Utils, VerbosePuts Classes: Generator

Constant Summary collapse

VERSION =

ContextSpook version

'1.5.1'
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, format: nil, &block) ⇒ ContextSpook::Generator::Context

The generate_context method creates a context object by either evaluating a block or parsing a file

This method serves as the primary entry point for generating context data. It accepts either a filename pointing to a context definition file or a block containing the context definition. The method handles the creation of a generator instance, processes the context definition, and returns the resulting context object.

Parameters:

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

    the path to a context definition file, or nil if using a block

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

    flag to enable verbose output during processing

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

    the output format for the context, either ‘JSON’ or ‘TOON’

  • block (Proc)

    a block containing the context definition, used if filename is nil

Returns:

Raises:

  • (ArgumentError)

    if neither a filename nor a block is provided

  • (ArgumentError)

    if an invalid format is specified

  • (ArgumentError)

    if the context definition file cannot be read or parsed



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/context_spook/generator.rb', line 40

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