Class: Blix::Cli::FileOperation

Inherits:
Operation show all
Defined in:
lib/blix/cli/operations/file.rb

Overview

create a file system directory

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/blix/cli/operations/file.rb', line 7

def content
  @content
end

#pathObject (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

#descriptionObject



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

#runObject



26
27
28
# File 'lib/blix/cli/operations/file.rb', line 26

def run
  File.write(path, content || '')
end

#undoObject



30
31
32
# File 'lib/blix/cli/operations/file.rb', line 30

def undo
  #File.unlink(path)
end