From 7bdb778159c1b0267c4d4fd7be18408f63a706e3 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Thu, 9 Oct 2014 19:54:32 +0000 Subject: [PATCH] Refactor action arguments checks --- lib/producer/core/action.rb | 6 ++++++ lib/producer/core/actions/file_append.rb | 5 +---- lib/producer/core/actions/file_writer.rb | 5 +---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/producer/core/action.rb b/lib/producer/core/action.rb index 3caef17..74ea046 100644 --- a/lib/producer/core/action.rb +++ b/lib/producer/core/action.rb @@ -30,6 +30,12 @@ module Producer def inspect_arguments @arguments.inspect[0, INSPECT_ARGUMENTS_SUM_LEN - name.length] end + + def check_arguments_size!(size) + if arguments.compact.size != size + fail ArgumentError, '`%s\' action requires %d arguments' % [name, size] + end + end end end end diff --git a/lib/producer/core/actions/file_append.rb b/lib/producer/core/actions/file_append.rb index 9d33dc9..63caa9b 100644 --- a/lib/producer/core/actions/file_append.rb +++ b/lib/producer/core/actions/file_append.rb @@ -3,10 +3,7 @@ module Producer module Actions class FileAppend < Action def setup - if arguments.compact.size != 2 - fail ArgumentError, '`%s\' action requires 2 arguments' % name - end - + check_arguments_size! 2 @path, @content = arguments end diff --git a/lib/producer/core/actions/file_writer.rb b/lib/producer/core/actions/file_writer.rb index 245d008..e432380 100644 --- a/lib/producer/core/actions/file_writer.rb +++ b/lib/producer/core/actions/file_writer.rb @@ -3,10 +3,7 @@ module Producer module Actions class FileWriter < Action def setup - if arguments.compact.size != 2 - fail ArgumentError, '`%s\' action requires 2 arguments' % name - end - + check_arguments_size! 2 @path, @content = arguments @options[:permissions] = @options.delete :mode if options.key? :mode @options[:owner] = @options.delete :user if options.key? :user