Class: Rundoc::CodeCommand::WriteRunner
- Inherits:
-
Object
- Object
- Rundoc::CodeCommand::WriteRunner
- Includes:
- FileUtil
- Defined in:
- lib/rundoc/code_command/write.rb
Constant Summary collapse
- NEWLINE =
Object.new
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #call(env = {}) ⇒ Object
-
#initialize(user_args:, render_command:, render_result:, io:, contents: nil) ⇒ WriteRunner
constructor
A new instance of WriteRunner.
- #render_command? ⇒ Boolean
- #to_md(env) ⇒ Object
Methods included from FileUtil
Constructor Details
#initialize(user_args:, render_command:, render_result:, io:, contents: nil) ⇒ WriteRunner
Returns a new instance of WriteRunner.
42 43 44 45 46 47 |
# File 'lib/rundoc/code_command/write.rb', line 42 def initialize(user_args:, render_command:, render_result:, io:, contents: nil) @filename = user_args.path.to_s @io = io @render_command = render_command @contents = contents.dup if contents && !contents.empty? end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
40 41 42 |
# File 'lib/rundoc/code_command/write.rb', line 40 def contents @contents end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
40 41 42 |
# File 'lib/rundoc/code_command/write.rb', line 40 def io @io end |
Instance Method Details
#call(env = {}) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/rundoc/code_command/write.rb', line 64 def call(env = {}) io.puts "Writing to: '#{filename}'" mkdir_p File.write(filename, contents) contents end |
#render_command? ⇒ Boolean
49 50 51 |
# File 'lib/rundoc/code_command/write.rb', line 49 def render_command? @render_command end |
#to_md(env) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rundoc/code_command/write.rb', line 53 def to_md(env) if render_command? if env[:commands].any? { |c| c[:visibility].not_hidden? } raise "must call write in its own code section" end env[:before] << "In file `#{filename}` write:" env[:before] << NEWLINE end nil end |