Sha256: 6ef334cbfe2844bfcfbb229b978fe0b1c30c9a83bac01b763a35f09818906769
Contents?: true
Size: 993 Bytes
Versions: 27
Compression:
Stored size: 993 Bytes
Contents
# frozen_string_literal: true require 'dato/dump/format' module Dato 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) 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*datocms:start.*#\s*datocms:end|\Z)/m, "\n\n# datocms:start\n#{content_to_add}\n# datocms:end" ) File.open(complete_path, 'w') do |f| f.write new_content end end end end end end
Version data entries
27 entries across 27 versions & 1 rubygems