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

Version information for the ContextSpook gem.

This module is auto-generated by GemHadar and exposes the current release version as a set of constants. Do not edit it by hand; it is rewritten on every rake version invocation.

Defined Under Namespace

Modules: OutputContext, TOON, Utils, VerbosePuts Classes: Generator

Constant Summary collapse

VERSION =

The current version of the ContextSpook gem as a String.

'1.8.0'
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, manifest: false, &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'

  • manifest (TrueClass, FalseClass) (defaults to: false) —

    if true, file entries omit their content and only carry metadata

  • 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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/context_spook/generator.rb', line 42

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