summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-03-21 11:54:04 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-03-21 13:53:29 -0700
commitaa2241ab17bc131c80f358f87006099fb108fb04 (patch)
tree2e827cb0b52f11ea2a9805c7439894b2c1d558e3 /lib
parenta3f7e9cd52e8901cbfc5dfa3d93c032dec2ddb7e (diff)
downloadchef-aa2241ab17bc131c80f358f87006099fb108fb04.tar.gz
allow use_inline_resources for core chef providers
* removes the DSL from InlineResources class * ActionClass is now responsible for mixing the DSL into action classes * apt_update provider converted over to use new syntax - does not need to mixin DeclareResource DSL - declares use_inline_resources - uses declare_resource instead of build_resource - converts def action_stuff to action :stuff - uses an execute resource instead of shell_out! - does not need the converge_by to update the action
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/provider.rb3
-rw-r--r--lib/chef/provider/apt_update.rb25
-rw-r--r--lib/chef/resource.rb6
-rw-r--r--lib/chef/resource/action_class.rb3
4 files changed, 19 insertions, 18 deletions
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb
index cef95a4db8..ebabb7b9eb 100644
--- a/lib/chef/provider.rb
+++ b/lib/chef/provider.rb
@@ -390,9 +390,6 @@ class Chef
end
end
end
-
- require "chef/dsl/recipe"
- include Chef::DSL::Recipe
end
protected
diff --git a/lib/chef/provider/apt_update.rb b/lib/chef/provider/apt_update.rb
index 449b298804..542d273339 100644
--- a/lib/chef/provider/apt_update.rb
+++ b/lib/chef/provider/apt_update.rb
@@ -22,7 +22,7 @@ require "chef/dsl/declare_resource"
class Chef
class Provider
class AptUpdate < Chef::Provider
- include Chef::DSL::DeclareResource
+ use_inline_resources
provides :apt_update, os: "linux"
@@ -36,18 +36,14 @@ class Chef
def load_current_resource
end
- def action_periodic
+ action :periodic do
if !apt_up_to_date?
- converge_by "update new lists of packages" do
- do_update
- end
+ do_update
end
end
- def action_update
- converge_by "force update new lists of packages" do
- do_update
- end
+ action :update do
+ do_update
end
private
@@ -62,16 +58,17 @@ class Chef
def do_update
[STAMP_DIR, APT_CONF_DIR].each do |d|
- build_resource(:directory, d, caller[0]) do
+ declare_resource(:directory, d, caller[0]) do
recursive true
- end.run_action(:create)
+ end
end
- build_resource(:file, "#{APT_CONF_DIR}/15update-stamp", caller[0]) do
+ declare_resource(:file, "#{APT_CONF_DIR}/15update-stamp", caller[0]) do
content "APT::Update::Post-Invoke-Success {\"touch #{STAMP_DIR}/update-success-stamp 2>/dev/null || true\";};"
- end.run_action(:create_if_missing)
+ action :create_if_missing
+ end
- shell_out!("apt-get -q update")
+ declare_resource(:execute, "apt-get -q update", caller[0])
end
end
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 21b2308688..53b4c52052 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -1316,7 +1316,11 @@ class Chef
# life as well.
@@sorted_descendants = nil
def self.sorted_descendants
- @@sorted_descendants ||= descendants.sort_by { |x| x.to_s }
+ # so it turns out Class.to_s just blindly returns the name of the class,
+ # which can be a Symbol in addition to being a String. as a result, we
+ # may get a Symbol back from Class.to_s, so we call #to_s on that again.
+ # (buggy on at least ruby-2.4.4)
+ @@sorted_descendants ||= descendants.sort_by { |x| x.to_s.to_s }
end
def self.inherited(child)
diff --git a/lib/chef/resource/action_class.rb b/lib/chef/resource/action_class.rb
index 3d9f2f3e7c..89b23499d0 100644
--- a/lib/chef/resource/action_class.rb
+++ b/lib/chef/resource/action_class.rb
@@ -17,10 +17,13 @@
#
require "chef/exceptions"
+require "chef/dsl/recipe"
class Chef
class Resource
module ActionClass
+ include Chef::DSL::Recipe
+
def to_s
"#{new_resource || "<no resource>"} action #{action ? action.inspect : "<no action>"}"
end