diff options
author | Tim Smith <tsmith@chef.io> | 2018-04-30 10:48:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-30 10:48:29 -0700 |
commit | dbb6935b9201d0b8201ed616c01b0d40034d3277 (patch) | |
tree | 4a85e56480de1ffd659c78fa13469001045f923b | |
parent | 6d6d3ef02e447bed5a2938dfb2aa261d07d68d60 (diff) | |
parent | 1e8d310fe93e6ebcc6b40f76e2ad754701051d0a (diff) | |
download | chef-dbb6935b9201d0b8201ed616c01b0d40034d3277.tar.gz |
Merge pull request #7204 from chef/remote_directory
Convert some of remote_directory to use properties
-rw-r--r-- | lib/chef/resource/remote_directory.rb | 50 | ||||
-rw-r--r-- | spec/unit/resource/remote_directory_spec.rb | 7 |
2 files changed, 9 insertions, 48 deletions
diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb index 677f358cc2..14e4f4a497 100644 --- a/lib/chef/resource/remote_directory.rb +++ b/lib/chef/resource/remote_directory.rb @@ -41,16 +41,11 @@ class Chef def initialize(name, run_context = nil) super @path = name - @source = ::File.basename(name) @delete = false @recursive = true - @purge = false - @files_backup = 5 @files_owner = nil @files_group = nil @files_mode = 0644 unless Chef::Platform.windows? - @overwrite = true - @cookbook = nil end if Chef::Platform.windows? @@ -58,29 +53,11 @@ class Chef rights_attribute(:files_rights) end - def source(args = nil) - set_or_return( - :source, - args, - :kind_of => String - ) - end - - def files_backup(arg = nil) - set_or_return( - :files_backup, - arg, - :kind_of => [ Integer, FalseClass ] - ) - end - - def purge(arg = nil) - set_or_return( - :purge, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end + property :source, String, default: lazy { ::File.basename(path) } + property :files_backup, [ Integer, FalseClass ], default: 5, desired_state: false + property :purge, [ TrueClass, FalseClass ], default: false, desired_state: false + property :overwrite, [ TrueClass, FalseClass ], default: false + property :cookbook, String def files_group(arg = nil) set_or_return( @@ -105,23 +82,6 @@ class Chef :regex => Chef::Config[:user_valid_regex] ) end - - def overwrite(arg = nil) - set_or_return( - :overwrite, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end - - def cookbook(args = nil) - set_or_return( - :cookbook, - args, - :kind_of => String - ) - end - end end end diff --git a/spec/unit/resource/remote_directory_spec.rb b/spec/unit/resource/remote_directory_spec.rb index c016213c4a..8ec2d80bc8 100644 --- a/spec/unit/resource/remote_directory_spec.rb +++ b/spec/unit/resource/remote_directory_spec.rb @@ -22,7 +22,7 @@ describe Chef::Resource::RemoteDirectory do let(:resource) { Chef::Resource::RemoteDirectory.new("/etc/dunk") } - it "sets the path to the first argument to new" do + it "path is the name property" do expect(resource.path).to eql("/etc/dunk") end @@ -32,7 +32,8 @@ describe Chef::Resource::RemoteDirectory do end it "has the basename of the remote directory resource as the default source" do - expect(resource.source).to eql("dunk") + resource.path "/foo/bar" + expect(resource.source).to eql("bar") end it "accepts a number for the remote files backup" do @@ -45,7 +46,7 @@ describe Chef::Resource::RemoteDirectory do expect(resource.files_backup).to eql(false) end - it "accepts 3 or 4 digets for the files_mode" do + it "accepts 3 or 4 digits for the files_mode" do resource.files_mode 100 expect(resource.files_mode).to eql(100) resource.files_mode 1000 |