diff options
author | Tim Smith <tsmith@chef.io> | 2017-12-14 15:02:16 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-12-15 08:16:28 -0800 |
commit | 3b55abbb30fcb6a8cbb4f58b16023bcfc38a44f3 (patch) | |
tree | 97324b9ef0f8bb39948a0682712da81aade49646 /lib | |
parent | 1c487ab5977446746f9b389e429707ec8142b063 (diff) | |
download | chef-3b55abbb30fcb6a8cbb4f58b16023bcfc38a44f3.tar.gz |
Avoid a few initializers in resources by using the DSL we have
Tip of the iceberg here, but it's the low hanging fruit
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/resource/cab_package.rb | 6 | ||||
-rw-r--r-- | lib/chef/resource/chocolatey_package.rb | 6 | ||||
-rw-r--r-- | lib/chef/resource/dsc_script.rb | 1 | ||||
-rw-r--r-- | lib/chef/resource/env.rb | 1 | ||||
-rw-r--r-- | lib/chef/resource/msu_package.rb | 11 | ||||
-rw-r--r-- | lib/chef/resource/windows_task.rb | 14 |
6 files changed, 11 insertions, 28 deletions
diff --git a/lib/chef/resource/cab_package.rb b/lib/chef/resource/cab_package.rb index b7acfb0ec9..73e639814d 100644 --- a/lib/chef/resource/cab_package.rb +++ b/lib/chef/resource/cab_package.rb @@ -24,15 +24,11 @@ class Chef class CabPackage < Chef::Resource::Package include Chef::Mixin::Uris + resource_name :cab_package provides :cab_package, os: "windows" allowed_actions :install, :remove - def initialize(name, run_context = nil) - super - @resource_name = :cab_package - end - property :source, String, coerce: (proc do |s| unless s.nil? diff --git a/lib/chef/resource/chocolatey_package.rb b/lib/chef/resource/chocolatey_package.rb index a443b9a1d7..77bdcb197a 100644 --- a/lib/chef/resource/chocolatey_package.rb +++ b/lib/chef/resource/chocolatey_package.rb @@ -22,15 +22,11 @@ class Chef class Resource class ChocolateyPackage < Chef::Resource::Package + resource_name :chocolatey_package provides :chocolatey_package, os: "windows" allowed_actions :install, :upgrade, :remove, :uninstall, :purge, :reconfig - def initialize(name, run_context = nil) - super - @resource_name = :chocolatey_package - end - # windows can't take Array options yet property :options, String diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb index 7da29a651a..7682c7e778 100644 --- a/lib/chef/resource/dsc_script.rb +++ b/lib/chef/resource/dsc_script.rb @@ -24,6 +24,7 @@ class Chef class DscScript < Chef::Resource include Chef::DSL::Powershell + resource_name :dsc_script provides :dsc_script, os: "windows" default_action :run diff --git a/lib/chef/resource/env.rb b/lib/chef/resource/env.rb index 746369f02d..7071be4b91 100644 --- a/lib/chef/resource/env.rb +++ b/lib/chef/resource/env.rb @@ -20,6 +20,7 @@ class Chef class Resource class Env < Chef::Resource + resource_name :env provides :env, os: "windows" default_action :create diff --git a/lib/chef/resource/msu_package.rb b/lib/chef/resource/msu_package.rb index 753992c185..c297f5b858 100644 --- a/lib/chef/resource/msu_package.rb +++ b/lib/chef/resource/msu_package.rb @@ -24,23 +24,18 @@ class Chef class MsuPackage < Chef::Resource::Package include Chef::Mixin::Uris + resource_name :msu_package provides :msu_package, os: "windows" allowed_actions :install, :remove - - def initialize(name, run_context = nil) - super - @resource_name = :msu_package - @source = name - @action = :install - end + default_action :install property :source, String, coerce: (proc do |s| unless s.nil? uri_scheme?(s) ? s : Chef::Util::PathHelper.canonical_path(s, false) end - end) + end), name_property: true property :checksum, String, desired_state: false end end diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb index 78076e08e5..a5fead7b13 100644 --- a/lib/chef/resource/windows_task.rb +++ b/lib/chef/resource/windows_task.rb @@ -22,19 +22,13 @@ class Chef class Resource class WindowsTask < Chef::Resource + resource_name: :windows_task provides :windows_task, os: "windows" allowed_actions :create, :delete, :run, :end, :enable, :disable default_action :create - def initialize(name, run_context = nil) - super - @resource_name = :windows_task - @task_name = name - @action = :create - end - - property :task_name, String, regex: [/\A[^\/\:\*\?\<\>\|]+\z/] + property :task_name, String, regex: [/\A[^\/\:\*\?\<\>\|]+\z/], name_property: true property :command, String property :cwd, String property :user, String, default: "SYSTEM" @@ -59,7 +53,7 @@ class Chef property :months, String property :idle_time, Integer property :random_delay, [String, Integer] - property :execution_time_limit, [String, Integer], default: "PT72H" # 72 hours in ISO08601 duration format + property :execution_time_limit, [String, Integer], default: "PT72H" # 72 hours in ISO8601 duration format attr_accessor :exists, :status, :enabled @@ -71,7 +65,7 @@ class Chef end if execution_time_limit - unless execution_time_limit == "PT72H" # don't double convert an iso08601 format duration + unless execution_time_limit == "PT72H" # don't double convert an ISO8601 format duration raise ArgumentError, "Invalid value passed for `execution_time_limit`. Please pass seconds as an Integer (e.g. 60) or a String with numeric values only (e.g. '60')." unless numeric_value_in_string?(execution_time_limit) duration = sec_to_dur(execution_time_limit) execution_time_limit(duration) |