From 602e09a72c6617ee01ca3febb519d3fd36bd2b8c Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Mon, 23 Nov 2015 19:59:02 -0800 Subject: dpkg multipackage and bonus fixes - multipackages dpkg_package - fixes edge conditions in load-current-resource around purging/removing packages that threw errors before - fixes the ability to purge packages that have been removed - adds a lot of functional tests for dpkg_package --- lib/chef/mixin/get_source_from_package.rb | 9 +++++-- lib/chef/mixin/subclass_directive.rb | 42 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 lib/chef/mixin/subclass_directive.rb (limited to 'lib/chef/mixin') diff --git a/lib/chef/mixin/get_source_from_package.rb b/lib/chef/mixin/get_source_from_package.rb index 2ed251854a..cb5583b431 100644 --- a/lib/chef/mixin/get_source_from_package.rb +++ b/lib/chef/mixin/get_source_from_package.rb @@ -1,5 +1,5 @@ # Author:: Lamont Granquist () -# Copyright:: Copyright (c) 2008 Opscode, Inc. +# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,6 +27,12 @@ class Chef module Mixin module GetSourceFromPackage + # FIXME: this is some bad code that I wrote a long time ago. + # - it does too much in the initializer + # - it mutates the new_resource + # - it does not support multipackage arrays + # this code is deprecated, check out the :use_package_names_for_source + # subclass directive instead def initialize(new_resource, run_context) super return if new_resource.package_name.is_a?(Array) @@ -40,4 +46,3 @@ class Chef end end end - diff --git a/lib/chef/mixin/subclass_directive.rb b/lib/chef/mixin/subclass_directive.rb new file mode 100644 index 0000000000..c0c7aa0328 --- /dev/null +++ b/lib/chef/mixin/subclass_directive.rb @@ -0,0 +1,42 @@ +# +# Author:: Adam Jacob () +# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class Chef + module Mixin + module SubclassDirective + def self.included(base) + base.extend(ClassMethods) + end + module ClassMethods + def subclass_directive(sym) + define_singleton_method sym do + instance_variable_set(:"@#{sym}", true) + end + + define_singleton_method :"#{sym}?" do + !!instance_variable_get(:"@#{sym}") + end + + define_method :"#{sym}?" do + self.class.send(:"#{sym}?") + end + end + end + end + end +end -- cgit v1.2.1