compat_resource 12.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ module ChefCompat
2
+ module DelegatingClass
3
+ def method_missing(name, *args, &block)
4
+ @delegates_to.send(name, *args, &block)
5
+ end
6
+ def const_missing(name)
7
+ @delegates_to.const_get(name)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ require 'chef_compat/monkeypatches/chef'
2
+ require 'chef_compat/monkeypatches/chef/resource'
3
+ require 'chef_compat/monkeypatches/chef/provider'
4
+ require 'chef_compat/monkeypatches/chef/resource/lwrp_base'
5
+ require 'chef_compat/monkeypatches/chef/exceptions'
@@ -0,0 +1,3 @@
1
+ class Chef
2
+ NOT_PASSED = Object.new if !defined?(NOT_PASSED)
3
+ end
@@ -0,0 +1,7 @@
1
+ class Chef
2
+ class Exceptions
3
+ # Used in Resource::ActionClass#load_current_resource to denote that
4
+ # the resource doesn't actually exist (for example, the file does not exist)
5
+ class CurrentValueDoesNotExist < RuntimeError; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'chef/provider'
2
+
3
+ class Chef::Provider
4
+ if !defined?(InlineResources)
5
+ InlineResources = Chef::Provider::LWRPBase::InlineResources
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ require 'chef/resource'
2
+
3
+ class Chef
4
+ class Resource
5
+ if !method_defined?(:current_value)
6
+ #
7
+ # Get the current actual value of this resource.
8
+ #
9
+ # This does not cache--a new value will be returned each time.
10
+ #
11
+ # @return A new copy of the resource, with values filled in from the actual
12
+ # current value.
13
+ #
14
+ def current_value
15
+ provider = provider_for_action(Array(action).first)
16
+ if provider.whyrun_mode? && !provider.whyrun_supported?
17
+ raise "Cannot retrieve #{self.class.current_resource} in why-run mode: #{provider} does not support why-run"
18
+ end
19
+ provider.load_current_resource
20
+ provider.current_resource
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,61 @@
1
+ require 'chef_compat/resource'
2
+ require 'chef/resource/lwrp_base'
3
+
4
+ module ChefCompat
5
+ module Monkeypatches
6
+ #
7
+ # NOTE: LOTS OF METAPROGRAMMING HERE. NOT FOR FAINT OF HEART.
8
+ #
9
+
10
+ # Add an empty module to Class so we can temporarily override it in build_from_file
11
+ module Class
12
+ end
13
+ class<<::Class
14
+ prepend(ChefCompat::Monkeypatches::Class)
15
+ end
16
+
17
+ module Chef
18
+ module Resource
19
+ module LWRPBase
20
+ def build_from_file(cookbook_name, filename, run_context)
21
+ # If the cookbook this LWRP is from depends on compat_resource, fix its LWRPs up real good
22
+ if run_context.cookbook_collection[cookbook_name].metadata.dependencies.has_key?('compat_resource')
23
+ # All cookbooks do Class.new(Chef::Resource::LWRPBase). Change Class.new
24
+ # temporarily to translate Chef::Resource::LWRPBase to ChefCompat::Resource
25
+ ChefCompat::Monkeypatches::Class.module_eval do
26
+ def new(*args, &block)
27
+ # Trick it! Use ChefCompat::Resource instead of Chef::Resource::LWRPBase
28
+ puts args.inspect
29
+ if args == [ ::Chef::Resource::LWRPBase ]
30
+ ChefCompat::Monkeypatches::Class.module_eval do
31
+ remove_method(:new) if method_defined?(:new)
32
+ end
33
+ args = [ ChefCompat::Resource ]
34
+ end
35
+ super(*args, &block)
36
+ end
37
+ end
38
+
39
+ begin
40
+
41
+ # Call the actual build_from_file
42
+ super
43
+
44
+ ensure
45
+ class<<ChefCompat::Monkeypatches::Class
46
+ remove_method(:new) if method_defined?(:new)
47
+ end
48
+ end
49
+ else
50
+ # Call the actual build_from_file
51
+ super
52
+ end
53
+ end
54
+ end
55
+ class <<::Chef::Resource::LWRPBase
56
+ prepend(LWRPBase)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,54 @@
1
+ require 'chef_compat/monkeypatches'
2
+ require 'chef_compat/copied_from_chef/chef/resource'
3
+
4
+ module ChefCompat
5
+ class Resource < ChefCompat::CopiedFromChef::Chef::Resource
6
+ # Things we'll need to define ourselves:
7
+ # 1. provider
8
+ # 2. resource_name
9
+
10
+ def provider(*args, &block)
11
+ super || self.class.action_class
12
+ end
13
+ def provider=(arg)
14
+ provider(arg)
15
+ end
16
+
17
+ if !respond_to?(:resource_name)
18
+ def self.resource_name(name=Chef::NOT_PASSED)
19
+ # Setter
20
+ if name != Chef::NOT_PASSED
21
+ # remove_canonical_dsl
22
+
23
+ # Set the resource_name and call provides
24
+ if name
25
+ name = name.to_sym
26
+ # If our class is not already providing this name, provide it.
27
+ # Commented out: use of resource_name and provides will need to be
28
+ # mutually exclusive in this world, generally.
29
+ # if !Chef::ResourceResolver.includes_handler?(name, self)
30
+ provides name#, canonical: true
31
+ # end
32
+ @resource_name = name
33
+ else
34
+ @resource_name = nil
35
+ end
36
+ end
37
+ @resource_name
38
+ end
39
+ def self.resource_name=(name)
40
+ resource_name(name)
41
+ end
42
+ end
43
+
44
+ # for LWRPBase
45
+ def self.run_context
46
+ @run_context
47
+ end
48
+ def self.run_context=(arg)
49
+ @run_context = arg
50
+ end
51
+ require 'chef/mixin/from_file'
52
+ extend Chef::Mixin::FromFile
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module ChefCompat
2
+ VERSION = '12.5.1' if !defined?(VERSION)
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compat_resource
3
+ version: !ruby/object:Gem::Version
4
+ version: 12.5.1
5
+ platform: ruby
6
+ authors:
7
+ - John Keiser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cheffish
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: stove
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Bring some new features of Chef to older versions
70
+ email: john@johnkeiser.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - CHANGELOG.md
76
+ - Gemfile
77
+ - LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - files/lib/chef_compat.rb
81
+ - files/lib/chef_compat/copied_from_chef.rb
82
+ - files/lib/chef_compat/copied_from_chef/chef/constants.rb
83
+ - files/lib/chef_compat/copied_from_chef/chef/delayed_evaluator.rb
84
+ - files/lib/chef_compat/copied_from_chef/chef/dsl/recipe.rb
85
+ - files/lib/chef_compat/copied_from_chef/chef/mixin/params_validate.rb
86
+ - files/lib/chef_compat/copied_from_chef/chef/property.rb
87
+ - files/lib/chef_compat/copied_from_chef/chef/provider.rb
88
+ - files/lib/chef_compat/copied_from_chef/chef/resource.rb
89
+ - files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb
90
+ - files/lib/chef_compat/delegating_class.rb
91
+ - files/lib/chef_compat/monkeypatches.rb
92
+ - files/lib/chef_compat/monkeypatches/chef.rb
93
+ - files/lib/chef_compat/monkeypatches/chef/exceptions.rb
94
+ - files/lib/chef_compat/monkeypatches/chef/provider.rb
95
+ - files/lib/chef_compat/monkeypatches/chef/resource.rb
96
+ - files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb
97
+ - files/lib/chef_compat/resource.rb
98
+ - files/lib/chef_compat/version.rb
99
+ homepage: http://chef.io
100
+ licenses:
101
+ - Apache 2.0
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - files/lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.4.5
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Bring some new features of Chef to older versions
123
+ test_files: []