Class: RailsAiBridge::Serializers::ContextFileSerializer
- Inherits:
-
Object
- Object
- RailsAiBridge::Serializers::ContextFileSerializer
- Defined in:
- lib/rails_ai_bridge/serializers/context_file_serializer.rb
Overview
Orchestrates writing context files to disk in various formats. Supports: CLAUDE.md, .cursorrules, .devinrules, .github/copilot-instructions.md, JSON Also generates split rule files for AI tools that support them.
Constant Summary collapse
- FORMAT_MAP =
{ claude: 'CLAUDE.md', codex: 'AGENTS.md', cursor: '.cursorrules', devin: '.devinrules', copilot: '.github/copilot-instructions.md', json: '.ai-context.json', gemini: 'GEMINI.md' }.freeze
- VALID_ON_CONFLICT_SYMBOLS =
%i[overwrite skip prompt].freeze
- UNMANAGEABLE_FORMATS =
Managed regions are markdown-comment delimited, so JSON output never participates.
%i[json].freeze
- DEFAULT_WRITE_OPTIONS =
Defaults applied when the caller omits the corresponding write option.
{ format: :all, split_rules: true, on_conflict: :overwrite, managed_region: nil }.freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#split_rules ⇒ Object
readonly
Returns the value of attribute split_rules.
Instance Method Summary collapse
-
#call ⇒ Hash{Symbol => Array<String>}
Write context files to the configured output directory, skipping unchanged ones.
-
#initialize(context, fingerprint:, **write_options) ⇒ ContextFileSerializer
constructor
A new instance of ContextFileSerializer.
Constructor Details
#initialize(context, fingerprint:, **write_options) ⇒ ContextFileSerializer
Returns a new instance of ContextFileSerializer.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rails_ai_bridge/serializers/context_file_serializer.rb', line 50 def initialize(context, fingerprint:, **) unknown = .keys - DEFAULT_WRITE_OPTIONS.keys raise ArgumentError, "Unknown write option(s): #{unknown.join(', ')}" unless unknown.empty? raise ArgumentError, 'fingerprint: is required; compute it with Fingerprinter.source_fingerprint(AppScope.current_app)' if !fingerprint || fingerprint.to_s.empty? = DEFAULT_WRITE_OPTIONS.merge() @context = context @format = [:format] @split_rules = [:split_rules] @conflict_policy = ConflictPolicy.build([:on_conflict]) @fingerprint = fingerprint managed_region = [:managed_region] @managed_region = managed_region.nil? ? RailsAiBridge.configuration.managed_region : managed_region end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/rails_ai_bridge/serializers/context_file_serializer.rb', line 9 def context @context end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
9 10 11 |
# File 'lib/rails_ai_bridge/serializers/context_file_serializer.rb', line 9 def format @format end |
#split_rules ⇒ Object (readonly)
Returns the value of attribute split_rules.
9 10 11 |
# File 'lib/rails_ai_bridge/serializers/context_file_serializer.rb', line 9 def split_rules @split_rules end |
Instance Method Details
#call ⇒ Hash{Symbol => Array<String>}
Write context files to the configured output directory, skipping unchanged ones.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rails_ai_bridge/serializers/context_file_serializer.rb', line 69 def call formats = format == :all ? FORMAT_MAP.keys : Array(format) output_dir = RailsAiBridge.configuration.output_dir_for(AppScope.current_app) written = [] skipped = [] = Time.now.utc.iso8601 LegacyAgentFiles.warn_once(formats) formats.each do |fmt| next if LegacyAgentFiles.skip_main?(fmt) process_format(fmt, output_dir, , @fingerprint, written, skipped) end generate_split_rules(formats, output_dir, written, skipped) if split_rules { written: written, skipped: skipped } end |