diff --git a/lib/producer/core/actions/file_append.rb b/lib/producer/core/actions/file_append.rb index 830196e..4c31e5b 100644 --- a/lib/producer/core/actions/file_append.rb +++ b/lib/producer/core/actions/file_append.rb @@ -2,27 +2,23 @@ module Producer module Core module Actions class FileAppend < Action + def setup + @path, @content = arguments + end + def name 'file_append' end def apply - fs.file_write path, combined_content - end - - def path - arguments[0] - end - - def content - arguments[1] + fs.file_write @path, combined_content end def combined_content - original_content = fs.file_read(path) + original_content = fs.file_read(@path) - return content unless original_content - original_content + content + return @content unless original_content + original_content + @content end end end diff --git a/lib/producer/core/actions/file_replace_content.rb b/lib/producer/core/actions/file_replace_content.rb index 7342f3a..2b4b741 100644 --- a/lib/producer/core/actions/file_replace_content.rb +++ b/lib/producer/core/actions/file_replace_content.rb @@ -2,28 +2,20 @@ module Producer module Core module Actions class FileReplaceContent < Action + def setup + @path, @pattern, @replacement = arguments + end + def name 'file_replace_content' end def apply - fs.file_write path, replaced_content - end - - def path - arguments[0] - end - - def pattern - arguments[1] - end - - def replacement - arguments[2] + fs.file_write @path, replaced_content end def replaced_content - fs.file_read(path).gsub pattern, replacement + fs.file_read(@path).gsub @pattern, @replacement end end end diff --git a/lib/producer/core/actions/file_writer.rb b/lib/producer/core/actions/file_writer.rb index 96ee6a5..82fbc3b 100644 --- a/lib/producer/core/actions/file_writer.rb +++ b/lib/producer/core/actions/file_writer.rb @@ -2,11 +2,10 @@ module Producer module Core module Actions class FileWriter < Action - def initialize(env, *args, **options) - super - @path, @content = arguments - @options[:permissions] = @options.delete :mode if @options.key? :mode - @options[:owner] = @options.delete :user if @options.key? :user + def setup + @path, @content = arguments + @options[:permissions] = @options.delete :mode if options.key? :mode + @options[:owner] = @options.delete :user if options.key? :user end def name diff --git a/lib/producer/core/actions/mkdir.rb b/lib/producer/core/actions/mkdir.rb index ae50576..c7884e9 100644 --- a/lib/producer/core/actions/mkdir.rb +++ b/lib/producer/core/actions/mkdir.rb @@ -2,8 +2,7 @@ module Producer module Core module Actions class Mkdir < Action - def initialize(env, *args, **options) - super + def setup @options[:permissions] = @options.delete :mode if @options.key? :mode @options[:owner] = @options.delete :user if @options.key? :user end diff --git a/spec/producer/core/actions/file_append_spec.rb b/spec/producer/core/actions/file_append_spec.rb index ed00d2f..bfc256a 100644 --- a/spec/producer/core/actions/file_append_spec.rb +++ b/spec/producer/core/actions/file_append_spec.rb @@ -20,18 +20,6 @@ module Producer::Core end end - describe '#path' do - it 'returns the file path' do - expect(action.path).to eq path - end - end - - describe '#content' do - it 'returns the content to append' do - expect(action.content).to eq added_content - end - end - describe '#combined_content' do it 'returns original content and added content combined' do expect(action.combined_content).to eq 'some content added' diff --git a/spec/producer/core/actions/file_replace_content_spec.rb b/spec/producer/core/actions/file_replace_content_spec.rb index a478ec9..d5528e4 100644 --- a/spec/producer/core/actions/file_replace_content_spec.rb +++ b/spec/producer/core/actions/file_replace_content_spec.rb @@ -21,24 +21,6 @@ module Producer::Core end end - describe '#path' do - it 'returns the file path' do - expect(action.path).to eq path - end - end - - describe '#pattern' do - it 'returns the pattern' do - expect(action.pattern).to eq pattern - end - end - - describe '#replacement' do - it 'returns the replacement' do - expect(action.replacement).to eq replacement - end - end - describe '#replaced_content' do it 'returns content with pattern occurrences pattern replaced' do expect(action.replaced_content).to eq 'some other content'