Implement `yaml_write' action

This commit is contained in:
Thibault Jouan
2014-10-11 00:47:16 +00:00
parent 9780cdf220
commit 0ba12bfb90
7 changed files with 76 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ module Producer
module Actions
class FileWriter < Action
def setup
check_arguments_size! 2
check_arguments_size! arguments_size
@path, @content = arguments
@options[:permissions] = @options.delete :mode if options.key? :mode
@options[:owner] = @options.delete :user if options.key? :user
@@ -17,6 +17,13 @@ module Producer
fs.file_write @path, @content
fs.setstat @path, @options unless @options.empty?
end
private
def arguments_size
2
end
end
end
end

View File

@@ -0,0 +1,23 @@
module Producer
module Core
module Actions
class YAMLWriter < FileWriter
def setup
super
@content = options.delete(:data).to_yaml
end
def name
'yaml_write'
end
private
def arguments_size
1
end
end
end
end
end

View File

@@ -23,6 +23,7 @@ module Producer
define_action :file_append, Actions::FileAppend
define_action :file_replace_content, Actions::FileReplaceContent
define_action :file_write, Actions::FileWriter
define_action :yaml_write, Actions::YAMLWriter
attr_reader :name, :actions, :condition