Sha256: 69b6fe88e5455cbf7a12f5f9ea1bf47e78fa37b96b5ad41c38428b8960d7c709
Contents?: true
Size: 1.03 KB
Versions: 4
Compression:
Stored size: 1.03 KB
Contents
# frozen_string_literal: true require 'agave/dump/format' module Agave module Dump module Operation class AddToDataFile attr_reader :context, :path, :format, :value def initialize(context, path, format, value) @context = context @path = path @format = format @value = value end def perform complete_path = File.join(context.path, path) FileUtils.mkdir_p(File.dirname(complete_path)) content_to_add = Format.dump(format, value) old_content = if File.exist? complete_path ::File.read(complete_path) else '' end new_content = old_content.sub( /\n*(#\s*agavecms:start.*#\s*agavecms:end|\Z)/m, "\n\n# agavecms:start\n#{content_to_add}\n# agavecms:end" ) File.open(complete_path, 'w') do |f| f.write new_content end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems