Implement `file_replace_content' task action

This commit is contained in:
Thibault Jouan
2014-03-05 01:59:38 +00:00
parent a7f6d7034b
commit d22b023ff4
7 changed files with 116 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ require 'producer/core/action'
require 'producer/core/actions/echo'
require 'producer/core/actions/shell_command'
require 'producer/core/actions/mkdir'
require 'producer/core/actions/file_replace_content'
require 'producer/core/actions/file_writer'
# condition tests (need to be defined before the condition DSL)

View File

@@ -0,0 +1,27 @@
module Producer
module Core
module Actions
class FileReplaceContent < Action
def apply
fs.file_write path, replaced_content
end
def path
arguments[0]
end
def pattern
arguments[1]
end
def replacement
arguments[2]
end
def replaced_content
fs.file_read(path).gsub pattern, replacement
end
end
end
end
end

View File

@@ -13,8 +13,9 @@ module Producer
define_action :echo, Actions::Echo
define_action :sh, Actions::ShellCommand
define_action :mkdir, Actions::Mkdir
define_action :file_write, Actions::FileWriter
define_action :mkdir, Actions::Mkdir
define_action :file_write, Actions::FileWriter
define_action :file_replace_content, Actions::FileReplaceContent
attr_reader :env, :block, :actions