Class: Rundoc::CodeCommand::FileCommand::Remove
Instance Attribute Summary
#command, #contents, #keyword, #original_args, #render_command, #render_result
Instance Method Summary
collapse
#filename, #mkdir_p
#hidden?, #not_hidden?, #push
Constructor Details
#initialize(filename) ⇒ Remove
5
6
7
|
# File 'lib/rundoc/code_command/file_command/remove.rb', line 5
def initialize(filename)
@filename = filename
end
|
Instance Method Details
#call(env = {}) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# 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) ⇒ Object
9
10
11
12
13
14
|
# 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
|