Class: RailsAiBridge::Serializers::RuleFileWriter
- Inherits:
-
Object
- Object
- RailsAiBridge::Serializers::RuleFileWriter
- Defined in:
- lib/rails_ai_bridge/serializers/rule_file_writer.rb
Overview
Writes generated Markdown files to disk with a diff guard: a file is written only when its generated content differs from the content on disk, so unchanged files keep their mtime and stay out of VCS diffs.
Instance Method Summary collapse
-
#call(files) ⇒ Hash{Symbol => Array<String>}
Writes each entry whose content differs from the file on disk, creating the target directory first.
-
#initialize(dir) ⇒ RuleFileWriter
constructor
A new instance of RuleFileWriter.
Constructor Details
#initialize(dir) ⇒ RuleFileWriter
Returns a new instance of RuleFileWriter.
12 13 14 |
# File 'lib/rails_ai_bridge/serializers/rule_file_writer.rb', line 12 def initialize(dir) @dir = dir end |
Instance Method Details
#call(files) ⇒ Hash{Symbol => Array<String>}
Writes each entry whose content differs from the file on disk,
creating the target directory first. Entries with nil content are
skipped without creating a file.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails_ai_bridge/serializers/rule_file_writer.rb', line 24 def call(files) FileUtils.mkdir_p(@dir) written = [] skipped = [] files.each do |filename, content| next unless content filepath = File.join(@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 |