Class: RailsAiBridge::Serializers::Providers::ClaudeRulesSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/serializers/providers/claude_rules_serializer.rb

Overview

Generates .claude/rules/ markdown files for Claude Code auto-discovery. Quick-reference lists keep ClaudeSerializer output smaller.

Constant Summary collapse

SEMANTIC_TIER_LIST_CAP =

Max model names listed per semantic tier in rails-context.md when Configuration#context_mode is :compact.

20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ ClaudeRulesSerializer

Returns a new instance of ClaudeRulesSerializer.

Parameters:



16
17
18
# File 'lib/rails_ai_bridge/serializers/providers/claude_rules_serializer.rb', line 16

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextHash (readonly)

Returns Introspection context passed to serializers.

Returns:

  • (Hash)

    Introspection context passed to serializers.



13
14
15
# File 'lib/rails_ai_bridge/serializers/providers/claude_rules_serializer.rb', line 13

def context
  @context
end

Instance Method Details

#call(output_dir) ⇒ Hash{Symbol => Array<String>}

Writes schema, models, and MCP reference files when content changes.

Write Claude rules Markdown files into the given output directory, updating only files whose generated content changed. Writes Claude rule Markdown files into the given output directory, creating or updating files under ".claude/rules".

Parameters:

  • output_dir (String)

    Root directory where .claude/rules is created.

  • output_dir (String)
    • Root directory where the .claude/rules files will be created.
  • output_dir (String)
    • Base directory where the ".claude/rules" folder will be created.

Returns:

  • (Hash{Symbol => Array<String>})

    Absolute file paths grouped by whether they were written or skipped because content was unchanged.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rails_ai_bridge/serializers/providers/claude_rules_serializer.rb', line 31

def call(output_dir)
  rules_dir = File.join(output_dir, '.claude', 'rules')
  FileUtils.mkdir_p(rules_dir)

  written = []
  skipped = []

  files = {
    'rails-context.md' => render_context_reference,
    'rails-schema.md' => render_schema_reference,
    'rails-models.md' => render_models_reference,
    'rails-mcp-tools.md' => render_mcp_tools_reference
  }

  files.each do |filename, content|
    next unless content

    filepath = File.join(rules_dir, filename)
    if File.exist?(filepath) && File.read(filepath) == content
      skipped << filepath
    else
      File.write(filepath, content)
      written << filepath
    end
  end

  { written: written, skipped: skipped }
end