Class: SleepingKingStudios::Docs::Commands::WriteFile

Inherits:
Cuprum::Command
  • Object
show all
Includes:
Cuprum::ExceptionHandling
Defined in:
lib/sleeping_king_studios/docs/commands/write_file.rb

Overview

Writes the given contents to a file.

Instance Method Summary collapse

Constructor Details

#initialize(force: false) ⇒ WriteFile

Returns a new instance of WriteFile.

Parameters:

  • force (Boolean) (defaults to: false)

    if true, overwrites an existing file.



29
30
31
32
33
# File 'lib/sleeping_king_studios/docs/commands/write_file.rb', line 29

def initialize(force: false)
  super()

  @force = force
end

Instance Method Details

#call(contents: , file_path: ) ⇒ Cuprum::Result, Cuprum::Result<Cuprum::Error>

Writes the given contents to the specified file.

Recursively generates the required directories, if needed.

Parameters:

  • contents (String) (defaults to: )

    the contents to write.

  • file_path (String) (defaults to: )

    the path of the file.

Returns:

  • (Cuprum::Result)

    a passing result if the directories are successfully created and the file is successfully written.

  • (Cuprum::Result<Cuprum::Error>)

    a failing result if the command was unable to create the directories or write the file.



# File 'lib/sleeping_king_studios/docs/commands/write_file.rb', line 15

#force?Boolean

Returns if true, overwrites an existing file.

Returns:

  • (Boolean)

    if true, overwrites an existing file.



36
37
38
# File 'lib/sleeping_king_studios/docs/commands/write_file.rb', line 36

def force?
  @force
end