class Rundoc::CodeCommand::FileCommand::Remove
Public Class Methods
new(filename)
click to toggle source
# File lib/rundoc/code_command/file_command/remove.rb, line 5 def initialize(filename) @filename = filename end
Public Instance Methods
call(env = {})
click to toggle source
# File lib/rundoc/code_command/file_command/remove.rb, line 16 def call(env = {}) puts "Deleting '#{contents.strip}' from #{filename}" raise "#{filename} does not exist" unless File.exist?(filename) regex = /^\s*#{Regexp.quote(contents)}/ doc = File.read(filename) doc.sub!(regex, '') File.open(filename, "w") do |f| f.write(doc) end contents end
to_md(env)
click to toggle source
# File lib/rundoc/code_command/file_command/remove.rb, line 9 def to_md(env) raise "must call write in its own code section" unless env[:commands].empty? before = env[:before] env[:before] = "In file `#{filename}` remove:\n\n#{before}" nil end