diff options
Diffstat (limited to 'lib/chef/resource/file.rb')
-rw-r--r-- | lib/chef/resource/file.rb | 137 |
1 files changed, 76 insertions, 61 deletions
diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb index 59c51ba8d3..3ea75c106b 100644 --- a/lib/chef/resource/file.rb +++ b/lib/chef/resource/file.rb @@ -18,6 +18,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # + class Chef class Resource class File < Chef::Resource @@ -28,83 +29,97 @@ class Chef @path = name @backup = true @action = "create" + @allowed_actions.push(:create, :delete, :touch) end def backup(arg=nil) - set_if_args(@backup, arg) do - case arg - when true, false, Integer - @backup = arg - else - raise ArgumentError, "backup must be true, false, or a number!" - end - end + set_or_return( + @backup, + arg, + { + :backup => arg, + }, + { + :backup => { + :kind_of => [ Integer, TrueClass, FalseClass ], + } + } + ) end - + def checksum(arg=nil) - set_if_args(@checksum, arg) do - case arg - when /^[a-zA-Z0-9]{32}$/ # md5sum - @checksum = arg - else - raise ArgumentError, "checksum must be an md5sum!" - end - end + set_or_return( + @checksum, + arg, + { + :checksum => arg, + }, + { + :checksum => { + :regex => /^[a-zA-Z0-9]{32}$/, + }, + } + ) end - - def action(arg=nil) - set_if_args(@action, arg) do - case arg - when "create", "delete" - @action = arg - else - raise ArgumentError, "action must be create or delete!" - end - end - end - + def group(arg=nil) - set_if_args(@group, arg) do - case arg - when /^([a-z]|[A-Z]|[0-9]|_|-)+$/, Integer - @group = arg - else - raise ArgumentError, "group must match /^([a-z]|[A-Z]|[0-9]|_|-)$/, Integer!" - end - end + set_or_return( + @group, + arg, + { + :group => arg + }, + { + :group => { + :regex => [ /^([a-z]|[A-Z]|[0-9]|_|-)+$/, /^\d+$/ ] + } + } + ) end def mode(arg=nil) - set_if_args(@mode, arg) do - case "#{arg.to_s}" - when /^\d{3,4}$/ - @mode = arg - else - raise ArgumentError, "mode must be a valid unix file mode - 3 or 4 digets!" - end - end + set_or_return( + @mode, + arg, + { + :mode => arg + }, + { + :mode => { + :regex => /^\d{3,4}$/ + } + } + ) end def owner(arg=nil) - set_if_args(@owner, arg) do - case arg - when /^([a-z]|[A-Z]|[0-9]|_|-)+$/, Integer - @owner = arg - else - raise ArgumentError, "group must match /^([a-z]|[A-Z]|[0-9]|_|-)$/, Integer!" - end - end + set_or_return( + @owner, + arg, + { + :owner => arg, + }, + { + :owner => { + :regex => [ /^([a-z]|[A-Z]|[0-9]|_|-)+$/, /^\d+$/ ] + } + } + ) end def path(arg=nil) - set_if_args(@path, arg) do - case arg - when String - @path = arg - else - raise ArgumentError, "path must be a string!" - end - end + set_or_return( + @path, + arg, + { + :path => arg, + }, + { + :path => { + :kind_of => String, + }, + } + ) end end |