Class: Rundoc::CodeCommand::FileCommand::Remove
- Inherits:
-
Rundoc::CodeCommand
- Object
- Rundoc::CodeCommand
- Rundoc::CodeCommand::FileCommand::Remove
- Includes:
- Rundoc::CodeCommand::FileUtil
- Defined in:
- lib/rundoc/code_command/file_command/remove.rb
Constant Summary
Constants inherited from Rundoc::CodeCommand
Instance Attribute Summary
Attributes inherited from Rundoc::CodeCommand
#command, #contents, #keyword, #original_args, #render_command, #render_result
Instance Method Summary collapse
- #call(env = {}) ⇒ Object
-
#initialize(filename) ⇒ Remove
constructor
A new instance of Remove.
- #to_md(env) ⇒ Object
Methods included from Rundoc::CodeCommand::FileUtil
Methods inherited from Rundoc::CodeCommand
Constructor Details
#initialize(filename) ⇒ Remove
Returns a new instance of 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 |
# 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.write(filename, doc) 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? env[:before] << "In file `#{filename}` remove:" env[:before] << NEWLINE nil end |