Module: Ace::Review::Molecules::SubjectStrategy

Defined in:
lib/ace/review/molecules/subject_strategy.rb

Overview

Factory and interface for subject splitting strategies

The SubjectStrategy module provides a factory method for creating strategies that determine how review subjects are split or processed before being sent to an LLM for review.

Available strategies:

  • :full - Pass-through strategy, no splitting (default)

  • :chunked - Split by logical boundaries (future)

  • :adaptive - Auto-select based on size (future)

Examples:

Factory usage

strategy = SubjectStrategy.for(:full, config)
strategy.can_handle?(subject_text, 128_000)
#=> true

Strategy lifecycle

strategy = SubjectStrategy.for(:full)
if strategy.can_handle?(subject, model_limit)
  units = strategy.prepare(subject, context)
  units.each { |unit| execute_review(unit) }
end

Constant Summary collapse

STRATEGIES =

Registry of available strategy classes

{
  full: "Ace::Review::Molecules::Strategies::FullStrategy",
  chunked: "Ace::Review::Molecules::Strategies::ChunkedStrategy",
  adaptive: "Ace::Review::Molecules::Strategies::AdaptiveStrategy"
}.freeze

Class Method Summary collapse

Class Method Details

.available?(type) ⇒ Boolean

Check if a strategy type is available

Parameters:

  • type (Symbol, String)

    Strategy type to check

Returns:

  • (Boolean)

    true if strategy is available



68
69
70
# File 'lib/ace/review/molecules/subject_strategy.rb', line 68

def self.available?(type)
  STRATEGIES.key?(type.to_sym)
end

.available_strategiesArray<Symbol>

List available strategy types

Returns:

  • (Array<Symbol>)

    List of available strategy types



75
76
77
# File 'lib/ace/review/molecules/subject_strategy.rb', line 75

def self.available_strategies
  STRATEGIES.keys
end

.for(type, config = {}) ⇒ Object

Factory method to create a strategy instance

Examples:

strategy = SubjectStrategy.for(:full)
strategy = SubjectStrategy.for(:chunked, chunk_size: 50_000)

Parameters:

  • type (Symbol)

    Strategy type (:full, :chunked, :adaptive)

  • config (Hash) (defaults to: {})

    Optional configuration for the strategy

Returns:

  • (Object)

    Strategy instance that responds to #can_handle? and #prepare

Raises:

  • (UnknownStrategyError)

    if strategy type is not recognized



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ace/review/molecules/subject_strategy.rb', line 46

def self.for(type, config = {})
  type_sym = type.to_sym
  class_name = STRATEGIES[type_sym]

  unless class_name
    available = STRATEGIES.keys.join(", ")
    raise Ace::Review::Errors::UnknownStrategyError,
      "Unknown strategy type '#{type}'. Available strategies: #{available}"
  end

  # Lazy require the strategy class
  require_strategy(type_sym)

  # Get the class and instantiate
  klass = Object.const_get(class_name)
  klass.new(config)
end