Class: Blix::Cli::FileOperation
- Defined in:
- lib/blix/cli/operations/file.rb
Overview
create a file system directory
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(path, content, overwrite = false) ⇒ FileOperation
constructor
A new instance of FileOperation.
- #run ⇒ Object
- #undo ⇒ Object
Methods inherited from Operation
#describe, describe_all, execute_all, list, new, old_new, #perform, reset!
Constructor Details
#initialize(path, content, overwrite = false) ⇒ FileOperation
Returns a new instance of FileOperation.
9 10 11 12 13 |
# File 'lib/blix/cli/operations/file.rb', line 9 def initialize(path, content, overwrite=false) @path = path @content = content @overwrite = overwrite end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
7 8 9 |
# File 'lib/blix/cli/operations/file.rb', line 7 def content @content end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/blix/cli/operations/file.rb', line 7 def path @path end |
Instance Method Details
#description ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/blix/cli/operations/file.rb', line 15 def description str = if File.file?(path) "overwrite file " else "create file " end str += path str += "*" if content str end |
#run ⇒ Object
26 27 28 |
# File 'lib/blix/cli/operations/file.rb', line 26 def run File.write(path, content || '') end |
#undo ⇒ Object
30 31 32 |
# File 'lib/blix/cli/operations/file.rb', line 30 def undo #File.unlink(path) end |