Class: RailsAiContext::Serializers::CursorRulesSerializer
- Inherits:
-
Object
- Object
- RailsAiContext::Serializers::CursorRulesSerializer
- Defined in:
- lib/rails_ai_context/serializers/cursor_rules_serializer.rb
Overview
Generates .cursor/rules/*.mdc files (new Cursor MDC format) AND a .cursorrules legacy fallback at the project root.
Why both:
- .cursor/rules/*.mdc is the recommended format for Cursor 0.42+
with per-file scoping (alwaysApply / globs / description triggers)
- .cursorrules is still consulted by Cursor's chat agent in many
versions and is the only format older clients understand. Real
user report (v5.9.0 release QA): the chat agent didn't detect
rules written only as .cursor/rules/*.mdc; adding .cursorrules
alongside fixed it.
Constant Summary
Constants included from ToolGuideHelper
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#call(output_dir) ⇒ Hash
{ written: [paths], skipped: [paths] }.
-
#initialize(context) ⇒ CursorRulesSerializer
constructor
A new instance of CursorRulesSerializer.
Methods included from ToolGuideHelper
#build_tools_table, #render_tools_guide, #render_tools_guide_compact, #tool_call, #tool_count, #tool_mode, #tools_anti_hallucination_section, #tools_antipatterns_section, #tools_detail_guidance, #tools_header, #tools_intro, #tools_name_list, #tools_power_tool_section, #tools_rules_section, #tools_table, #tools_workflow_section
Methods included from StackOverviewHelper
#arch_labels_hash, #detect_before_actions, #detect_job_files, #detect_service_files, #full_preset_stack_lines, #model_extras_line, #notable_gems_list, #pattern_labels_hash, #project_root, #render_compact_controllers_list, #scope_names, #write_rule_files
Constructor Details
#initialize(context) ⇒ CursorRulesSerializer
Returns a new instance of CursorRulesSerializer.
24 25 26 |
# File 'lib/rails_ai_context/serializers/cursor_rules_serializer.rb', line 24 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
22 23 24 |
# File 'lib/rails_ai_context/serializers/cursor_rules_serializer.rb', line 22 def context @context end |
Instance Method Details
#call(output_dir) ⇒ Hash
Returns { written: [paths], skipped: [paths] }.
30 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 |
# File 'lib/rails_ai_context/serializers/cursor_rules_serializer.rb', line 30 def call(output_dir) rules_dir = File.join(output_dir, ".cursor", "rules") # Split rule files (.cursor/rules/*.mdc) are fully gem-owned — # written as-is with no markers (the gem manages every file in # that directory). mdc_files = { File.join(rules_dir, "rails-project.mdc") => render_project_rule, File.join(rules_dir, "rails-models.mdc") => render_models_rule, File.join(rules_dir, "rails-controllers.mdc") => render_controllers_rule, File.join(rules_dir, "rails-mcp-tools.mdc") => render_mcp_tools_rule } result = write_rule_files(mdc_files) # .cursorrules is at the project root and may pre-date the gem # install (users frequently hand-write .cursorrules before # adopting any tooling). Wrap it in BEGIN/END markers like # CLAUDE.md / AGENTS.md / .github/copilot-instructions.md so # user content above/below the gem-managed block survives every # `rails ai:context` regeneration. cursorrules_path = File.join(output_dir, ".cursorrules") case SectionMarkerWriter.write_with_markers(cursorrules_path, render_cursorrules_legacy) when :written then result[:written] << cursorrules_path when :skipped then result[:skipped] << cursorrules_path end result end |