Class: TyranoDsl::FileActions::CreateFile

Inherits:
Object
  • Object
show all
Includes:
FileActionsModule
Defined in:
lib/tyrano_dsl/file_actions/create_file.rb

Overview

Create a file with a custom content

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, content) ⇒ CreateFile

Returns a new instance of CreateFile.

Parameters:

  • path (String)
  • content (String)


15
16
17
18
19
# File 'lib/tyrano_dsl/file_actions/create_file.rb', line 15

def initialize(path, content)
  @path = path
  @content = content
  log {self.to_s}
end

Instance Attribute Details

#contentString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/tyrano_dsl/file_actions/create_file.rb', line 9

def content
  @content
end

#pathString (readonly)

Returns:

  • (String)


11
12
13
# File 'lib/tyrano_dsl/file_actions/create_file.rb', line 11

def path
  @path
end

Instance Method Details

#run(tyrano_project_path) ⇒ Object

Parameters:

  • tyrano_project_path (String)


22
23
24
25
26
27
# File 'lib/tyrano_dsl/file_actions/create_file.rb', line 22

def run(tyrano_project_path)
  full_path = File.join(tyrano_project_path, path)
  log {"Creating file [#{full_path}]"}
  create_parent_dir_if_not_exist(full_path)
  File.write(full_path, content)
end

#to_sObject



29
30
31
# File 'lib/tyrano_dsl/file_actions/create_file.rb', line 29

def to_s
  "Create file [#{path}]"
end