Implement `yaml_write' action
This commit is contained in:
@@ -17,6 +17,7 @@ require 'producer/core/actions/mkdir'
|
||||
require 'producer/core/actions/file_append'
|
||||
require 'producer/core/actions/file_replace_content'
|
||||
require 'producer/core/actions/file_writer'
|
||||
require 'producer/core/actions/yaml_writer'
|
||||
|
||||
# condition tests
|
||||
require 'producer/core/test'
|
||||
|
@@ -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
|
||||
|
23
lib/producer/core/actions/yaml_writer.rb
Normal file
23
lib/producer/core/actions/yaml_writer.rb
Normal 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
|
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user