Refactor action arguments checks
This commit is contained in:
parent
5549ebc676
commit
7bdb778159
@ -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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user