context_spook 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48da6b99283d3e0b02730a5ef6c02d07726dca15c7d29d6e40b73cc5d1f11e37
4
- data.tar.gz: 3c8f65d9f003f1c7053157beab50d95ff692852bca4c5efef83241c01ff2740c
3
+ metadata.gz: 5cca218e18443bf3698be556f93b822253a9f0dd4c93322d1ee9c826d1a26dc3
4
+ data.tar.gz: d8c48e20203cbc5c1c0741e93805480aa7fbe9987821fe2b9839447902879149
5
5
  SHA512:
6
- metadata.gz: 3f0c9d83fc057968a95f74dff08f035908ea9e362e608007046919acc7e9e5d0e2d6cc7a4e9526d24ba8d50cc5ca8c450b8537c4b4d4dead1910b429806a5978
7
- data.tar.gz: a6bea380021e97a6095c66418628e67cfa6afdcc1f85585a71d622d17355e5640f8cb64403c8eb196183753f260be40a20fc1c32dd7d39db1d24cae0f6518cbc
6
+ metadata.gz: a7f1fb4f2b26f9c59dc6a48be8db0a2ffc4381250334a401c6ad2944fe398cb18bcc0154df6111d26ceac1a9bcad7ac4386626aeb681bbe20f1286310fbe58f0
7
+ data.tar.gz: 990b7df25449551007c8e986ec479bdf5656195e47ef6d7243603849179a5fac6edaa6e245bbfaa99768115b3b46eeffc5baf6f37e542c8a4b729dc443ba8b13
data/Rakefile CHANGED
@@ -38,7 +38,7 @@ GemHadar do
38
38
  dependency 'mime-types', '~> 3.0'
39
39
  dependency 'yaml', '~> 0.4'
40
40
  dependency 'pathname', '~> 0.4'
41
- dependency 'ruby-json-toon', '~> 1.0'
41
+ dependency 'toon-ruby', '>= 0.1'
42
42
  development_dependency 'all_images', '~> 0.6'
43
43
  development_dependency 'rspec', '~> 3.2'
44
44
  development_dependency 'debug'
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: context_spook 1.4.0 ruby lib
2
+ # stub: context_spook 1.5.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "context_spook".freeze
6
- s.version = "1.4.0".freeze
6
+ s.version = "1.5.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -36,5 +36,5 @@ Gem::Specification.new do |s|
36
36
  s.add_runtime_dependency(%q<mime-types>.freeze, ["~> 3.0".freeze])
37
37
  s.add_runtime_dependency(%q<yaml>.freeze, ["~> 0.4".freeze])
38
38
  s.add_runtime_dependency(%q<pathname>.freeze, ["~> 0.4".freeze])
39
- s.add_runtime_dependency(%q<ruby-json-toon>.freeze, ["~> 1.0".freeze])
39
+ s.add_runtime_dependency(%q<toon-ruby>.freeze, [">= 0.1".freeze])
40
40
  end
@@ -13,28 +13,30 @@ require 'context_spook/output_context'
13
13
  module ContextSpook
14
14
  include DSLKit::Interpreter
15
15
 
16
- # The generate_context method processes a context definition file or block
17
- # and returns the resulting context object.
16
+ # The generate_context method creates a context object by either evaluating a
17
+ # block or parsing a file
18
18
  #
19
- # This method serves as the primary entry point for generating project
20
- # context data. It accepts either a filename pointing to a context definition
21
- # file or a block containing the context definition, but not both.
22
- # When a filename is provided, it reads and parses the file content. When a
23
- # block is provided, it evaluates the block within the generator's context.
24
- # The method ensures that only one context definition mechanism is used.
19
+ # This method serves as the primary entry point for generating context data.
20
+ # It accepts either a filename pointing to a context definition file or a
21
+ # block containing the context definition. The method handles the creation of
22
+ # a generator instance, processes the context definition, and returns the
23
+ # resulting context object.
25
24
  #
26
- # @param filename [ String, nil ] the path to the context definition file to
27
- # be processed
25
+ # @param filename [ String, nil ] the path to a context definition file, or
26
+ # nil if using a block
28
27
  # @param verbose [ TrueClass, FalseClass ] flag to enable verbose output
29
- # during processing, defaults to false.
30
- # @param block [ Proc ] a block containing the context definition to be
31
- # evaluated
28
+ # during processing
29
+ # @param format [ String, nil ] the output format for the context, either
30
+ # 'JSON' or 'TOON'
31
+ # @param block [ Proc ] a block containing the context definition, used if
32
+ # filename is nil
32
33
  #
33
- # @return [ ContextSpook::Generator::Context ] the context object generated
34
- # from the file contents or block
34
+ # @return [ ContextSpook::Generator::Context ] the generated context object containing
35
+ # project metadata, file contents, command outputs, and variables
35
36
  #
36
37
  # @raise [ ArgumentError ] if neither a filename nor a block is provided
37
- # @raise [ ArgumentError ] if both a filename and a block are provided
38
+ # @raise [ ArgumentError ] if an invalid format is specified
39
+ # @raise [ ArgumentError ] if the context definition file cannot be read or parsed
38
40
  def self.generate_context(filename = nil, verbose: false, format: nil, &block)
39
41
  verbose = !!verbose
40
42
  filename.present? ^ block or
@@ -80,6 +82,9 @@ module ContextSpook
80
82
  def initialize(verbose: false, format: nil, &block)
81
83
  @verbose = !!verbose
82
84
  @format = (format || 'JSON').upcase
85
+ %w[ TOON JSON ].include?(@format) or
86
+ raise ArgumentError,
87
+ "format needs to be either JSON or TOON, was #{@format.inspect}"
83
88
  block and instance_eval(&block)
84
89
  end
85
90
 
@@ -1,4 +1,4 @@
1
- require 'ruby_json_toon'
1
+ require 'toon'
2
2
 
3
3
  # The ContextSpook::TOON module provides TOON (Token-Oriented Object Notation)
4
4
  # serialization functionality for context objects.
@@ -7,7 +7,7 @@ module ContextSpook::TOON
7
7
  #
8
8
  # @return [String] the TOON-encoded representation of the context
9
9
  def to_toon
10
- RubyJsonToon.encode(as_json)
10
+ ::Toon.encode(as_json)
11
11
  end
12
12
  memoize method: :to_toon
13
13
 
@@ -1,6 +1,6 @@
1
1
  module ContextSpook
2
2
  # ContextSpook version
3
- VERSION = '1.4.0'
3
+ VERSION = '1.5.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -33,6 +33,21 @@ describe ContextSpook::Generator do
33
33
  described_class.send(:new).output_context_size
34
34
  end
35
35
 
36
+ context 'can handle formats' do
37
+ it 'raises exceptions for invalid formats' do
38
+ generator = described_class.send(:new, format: 'TOON')
39
+ expect(generator.format).to eq 'TOON'
40
+ end
41
+
42
+ it 'raises exceptions for invalid formats' do
43
+ expect {
44
+ described_class.send(:new, format: 'YAML')
45
+ }.to raise_error(
46
+ ArgumentError, /format needs to be either JSON or TOON, was "YAML"/
47
+ )
48
+ end
49
+ end
50
+
36
51
  it 'cannot do from block and filename' do
37
52
  expect {
38
53
  ContextSpook.generate_context('.contexts/project.rb') { }
@@ -20,8 +20,22 @@ describe ContextSpook::TOON do
20
20
 
21
21
  it 'produces valid TOON output' do
22
22
  toon_output = context.to_toon
23
- # TOON should be a valid string representation
24
- expect { RubyJsonToon.decode(toon_output) }.not_to raise_error
23
+ expect(toon_output).to match(
24
+ %r{
25
+ \Afiles:\n
26
+ ^[ ]{2}"lib/context_spook\.rb":\n
27
+ ^[ ]{4}content:[ ]"[^"]+"\n
28
+ ^[ ]{4}size:[ ]120\n
29
+ ^[ ]{4}lines:[ ]5\n
30
+ ^[ ]{4}content_types\[2\]:[ ]application/x-ruby,text/x-ruby\n
31
+ ^commands:\n
32
+ ^metadata:\n
33
+ ^[ ]{2}version:[ ]"1\.0"\n
34
+ ^[ ]{2}format:[ ]JSON\n
35
+ ^variables:\n
36
+ ^[ ]{2}foo:[ ]bar\z
37
+ }x
38
+ )
25
39
  end
26
40
  end
27
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: context_spook
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -178,19 +178,19 @@ dependencies:
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0.4'
180
180
  - !ruby/object:Gem::Dependency
181
- name: ruby-json-toon
181
+ name: toon-ruby
182
182
  requirement: !ruby/object:Gem::Requirement
183
183
  requirements:
184
- - - "~>"
184
+ - - ">="
185
185
  - !ruby/object:Gem::Version
186
- version: '1.0'
186
+ version: '0.1'
187
187
  type: :runtime
188
188
  prerelease: false
189
189
  version_requirements: !ruby/object:Gem::Requirement
190
190
  requirements:
191
- - - "~>"
191
+ - - ">="
192
192
  - !ruby/object:Gem::Version
193
- version: '1.0'
193
+ version: '0.1'
194
194
  description: |
195
195
  context_spook is a library that collects and organizes project
196
196
  information to help AI assistants understand codebases better.