Class: Ace::Review::Models::Reviewer

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/review/models/reviewer.rb

Overview

Represents a configured reviewer entity with focus areas and filtering capabilities.

Reviewers are configured entities that transform from simple model names to full-featured review participants with focus areas, file filtering, and weighted contributions.

Examples:

Creating a reviewer from config

reviewer = Reviewer.new(
  name: "code-fit",
  model: "google:gemini-2.5-pro",
  focus: "code_quality",
  system_prompt_additions: "Focus on SOLID principles...",
  file_patterns: { include: ["lib/**/*.rb"], exclude: ["**/*_test.rb"] },
  weight: 1.0,
  critical: false
)

Constant Summary collapse

DEFAULT_WEIGHT =

Default weight for reviewers (1.0 = full contribution)

1.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Reviewer

Initialize a new Reviewer from a configuration hash

Parameters:

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

    Configuration hash with reviewer settings

Options Hash (config):

  • :name (String)

    Human-readable name for the reviewer

  • :model (String)

    LLM model identifier (e.g., “google:gemini-2.5-pro”)

  • :focus (String)

    Review focus area (e.g., “code_quality”, “security”)

  • :system_prompt_additions (String)

    Additional system prompt text

  • :file_patterns (Hash)

    File filtering patterns

  • :weight (Float)

    Contribution weight (0.0-1.0, default: 1.0)

  • :critical (Boolean)

    Whether findings are always highlighted



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ace/review/models/reviewer.rb', line 40

def initialize(config = {})
  # Support both symbol and string keys
  config = normalize_keys(config)

  @name = config["name"]
  @model = config["model"]
  @focus = config["focus"]
  @system_prompt_additions = config["system_prompt_additions"]
  @file_patterns = normalize_file_patterns(config["file_patterns"])
  @weight = (config["weight"] || DEFAULT_WEIGHT).to_f
  @critical = config["critical"] || false

  validate!
end

Instance Attribute Details

#criticalObject (readonly)

Returns the value of attribute critical.



27
28
29
# File 'lib/ace/review/models/reviewer.rb', line 27

def critical
  @critical
end

#file_patternsObject (readonly)

Returns the value of attribute file_patterns.



27
28
29
# File 'lib/ace/review/models/reviewer.rb', line 27

def file_patterns
  @file_patterns
end

#focusObject (readonly)

Returns the value of attribute focus.



27
28
29
# File 'lib/ace/review/models/reviewer.rb', line 27

def focus
  @focus
end

#modelObject (readonly)

Returns the value of attribute model.



27
28
29
# File 'lib/ace/review/models/reviewer.rb', line 27

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/ace/review/models/reviewer.rb', line 27

def name
  @name
end

#system_prompt_additionsObject (readonly)

Returns the value of attribute system_prompt_additions.



27
28
29
# File 'lib/ace/review/models/reviewer.rb', line 27

def system_prompt_additions
  @system_prompt_additions
end

#weightObject (readonly)

Returns the value of attribute weight.



27
28
29
# File 'lib/ace/review/models/reviewer.rb', line 27

def weight
  @weight
end

Class Method Details

.from_preset_config(config) ⇒ Array<Reviewer>

Create Reviewers from preset config (new reviewers array format)

Parameters:

  • config (Hash)

    Preset configuration

Returns:

  • (Array<Reviewer>)

    Array of reviewer instances



59
60
61
62
63
64
65
66
67
68
# File 'lib/ace/review/models/reviewer.rb', line 59

def self.from_preset_config(config)
  config = normalize_hash_keys(config)

  # New format: reviewers array
  if config["reviewers"].is_a?(Array) && config["reviewers"].any?
    return config["reviewers"].map { |r| new(r) }
  end

  []
end

.normalize_hash_keys(hash) ⇒ Object

Class method for key normalization



163
164
165
166
# File 'lib/ace/review/models/reviewer.rb', line 163

def self.normalize_hash_keys(hash)
  return {} unless hash.is_a?(Hash)
  hash.transform_keys(&:to_s)
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Check equality with another reviewer

Parameters:

  • other (Reviewer)

    Other reviewer to compare

Returns:

  • (Boolean)

    True if equal



129
130
131
132
133
134
135
136
137
# File 'lib/ace/review/models/reviewer.rb', line 129

def ==(other)
  return false unless other.is_a?(Reviewer)

  name == other.name &&
    model == other.model &&
    focus == other.focus &&
    weight == other.weight &&
    critical == other.critical
end

#enhance_system_prompt(base_prompt) ⇒ String

Enhance system prompt with reviewer’s additions

Parameters:

  • base_prompt (String)

    Original system prompt

Returns:

  • (String)

    Enhanced prompt with reviewer additions



84
85
86
87
88
89
# File 'lib/ace/review/models/reviewer.rb', line 84

def enhance_system_prompt(base_prompt)
  return base_prompt unless system_prompt_additions
  return system_prompt_additions if base_prompt.nil? || base_prompt.empty?

  "#{base_prompt}\n\n#{system_prompt_additions}"
end

#filter_subject(subject) ⇒ Hash

Filter subject content based on reviewer’s file patterns

Delegates to SubjectFilter molecule for actual filtering logic.

Parameters:

  • subject (Hash)

    Subject configuration with files/diff/content

Returns:

  • (Hash)

    Filtered subject (deep copy with only matching content)



76
77
78
# File 'lib/ace/review/models/reviewer.rb', line 76

def filter_subject(subject)
  Molecules::SubjectFilter.filter(subject, file_patterns)
end

#has_file_patterns?Boolean

Check if this reviewer has file patterns configured

Delegates to SubjectFilter molecule.

Returns:

  • (Boolean)

    True if file patterns are configured



96
97
98
# File 'lib/ace/review/models/reviewer.rb', line 96

def has_file_patterns?
  Molecules::SubjectFilter.has_patterns?(file_patterns)
end

#hashInteger

Hash code for use in hash tables

Returns:

  • (Integer)

    Hash code



144
145
146
# File 'lib/ace/review/models/reviewer.rb', line 144

def hash
  [name, model, focus, weight, critical].hash
end

#matches_file?(file_path) ⇒ Boolean

Check if a file path matches this reviewer’s patterns

Delegates to SubjectFilter molecule.

Parameters:

  • file_path (String)

    File path to check

Returns:

  • (Boolean)

    True if file matches (or no patterns configured)



106
107
108
# File 'lib/ace/review/models/reviewer.rb', line 106

def matches_file?(file_path)
  Molecules::SubjectFilter.matches_file?(file_path, file_patterns)
end

#to_hHash

Convert to hash representation

Returns:

  • (Hash)

    Hash with string keys



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ace/review/models/reviewer.rb', line 113

def to_h
  {
    "name" => name,
    "model" => model,
    "focus" => focus,
    "system_prompt_additions" => system_prompt_additions,
    "file_patterns" => file_patterns,
    "weight" => weight,
    "critical" => critical
  }.compact
end