Refactor action arguments checks

This commit is contained in:
Thibault Jouan 2014-10-09 19:54:32 +00:00
parent 5549ebc676
commit 7bdb778159
3 changed files with 8 additions and 8 deletions

View File

@ -30,6 +30,12 @@ module Producer
def inspect_arguments def inspect_arguments
@arguments.inspect[0, INSPECT_ARGUMENTS_SUM_LEN - name.length] @arguments.inspect[0, INSPECT_ARGUMENTS_SUM_LEN - name.length]
end 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 end
end end

View File

@ -3,10 +3,7 @@ module Producer
module Actions module Actions
class FileAppend < Action class FileAppend < Action
def setup def setup
if arguments.compact.size != 2 check_arguments_size! 2
fail ArgumentError, '`%s\' action requires 2 arguments' % name
end
@path, @content = arguments @path, @content = arguments
end end

View File

@ -3,10 +3,7 @@ module Producer
module Actions module Actions
class FileWriter < Action class FileWriter < Action
def setup def setup
if arguments.compact.size != 2 check_arguments_size! 2
fail ArgumentError, '`%s\' action requires 2 arguments' % name
end
@path, @content = arguments @path, @content = arguments
@options[:permissions] = @options.delete :mode if options.key? :mode @options[:permissions] = @options.delete :mode if options.key? :mode
@options[:owner] = @options.delete :user if options.key? :user @options[:owner] = @options.delete :user if options.key? :user