chef-cookie_cutter 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/chef/cookie_cutter.rb +15 -10
- data/lib/chef/cookie_cutter/fancy_property.rb +15 -7
- data/lib/chef/cookie_cutter/{monkey_patches.rb → lwrp_build_params.rb} +0 -0
- data/lib/chef/cookie_cutter/lwrp_include.rb +6 -2
- data/lib/chef/cookie_cutter/namespace.rb +42 -28
- data/lib/chef/cookie_cutter/shared_blocks.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19608086c935f6ee87d275ff9817d97da4438cc3
|
4
|
+
data.tar.gz: 6d84cc99f20811b7fe1844839707462602a24b7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4257835cf95c912912e244ea69185b51002447e628ec0c23df1487128e880cd46a40b90e6539c098a3f563a952f62dace4afbe7e9eec2426555dced00ed5cfd7
|
7
|
+
data.tar.gz: e5c92a23027f27acf6be0bbdae83f6744c923d4605be2d93ee8edf1d323a71c8dd9f582c7c06ab4ae5c0acd0f33dc1342f5e6acb8fedf2b471439d4874b60460
|
data/lib/chef/cookie_cutter.rb
CHANGED
@@ -22,29 +22,34 @@ require 'chef/provider/lwrp_base'
|
|
22
22
|
|
23
23
|
class Chef
|
24
24
|
module CookieCutter
|
25
|
-
def self.chef_version(
|
26
|
-
::Gem::
|
25
|
+
def self.chef_version(constraint)
|
26
|
+
gem_version = ::Gem::Version.new(::Chef::VERSION)
|
27
|
+
::Gem::Requirement.new(constraint).satisfied_by?(gem_version)
|
27
28
|
end
|
28
29
|
|
29
30
|
if chef_version('~> 12.5.0.alpha')
|
30
31
|
require_relative 'cookie_cutter/fancy_property'
|
31
32
|
end
|
32
33
|
|
34
|
+
require_relative 'cookie_cutter/lwrp_build_params'
|
33
35
|
require_relative 'cookie_cutter/lwrp_include'
|
34
|
-
require_relative 'cookie_cutter/monkey_patches'
|
35
36
|
require_relative 'cookie_cutter/namespace'
|
36
37
|
require_relative 'cookie_cutter/run_state'
|
37
38
|
require_relative 'cookie_cutter/shared_blocks'
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
42
|
+
CC = Chef::CookieCutter
|
43
|
+
|
41
44
|
# Register Monkey Patches
|
42
|
-
Chef::
|
43
|
-
Chef::
|
45
|
+
Chef::Node.send :prepend, CC::MonkeyPatches::Node
|
46
|
+
Chef::Resource::LWRPBase.send :prepend, CC::MonkeyPatches::LWRPResource
|
47
|
+
Chef::Provider::LWRPBase.send :prepend, CC::MonkeyPatches::LWRPProvider
|
44
48
|
|
45
49
|
# Register DSL
|
46
|
-
Chef::Recipe.send
|
47
|
-
Chef::Resource.send
|
48
|
-
Chef::Provider.send
|
49
|
-
Chef::
|
50
|
-
Chef::
|
50
|
+
Chef::Recipe.send :include, CC::DSL
|
51
|
+
Chef::Resource.send :include, CC::DSL
|
52
|
+
Chef::Provider.send :include, CC::DSL
|
53
|
+
Chef::Node.send :include, CC::AttributeDSL
|
54
|
+
Chef::Resource::LWRPBase.send :extend, CC::ResourceDSL
|
55
|
+
Chef::Provider::LWRPBase.send :extend, CC::ProviderDSL
|
@@ -44,14 +44,9 @@ class Chef
|
|
44
44
|
|
45
45
|
def coerce(resource, *args, **kwargs, &blk)
|
46
46
|
if options.key?(:coerce_class)
|
47
|
-
|
48
|
-
value.instance_eval(&blk) if block_given?
|
49
|
-
value
|
47
|
+
coerce_class(options[:coerce_class], *args, **kwargs, &blk)
|
50
48
|
elsif options.key?(:coerce)
|
51
|
-
|
52
|
-
value.instance_eval(&blk) if block_given?
|
53
|
-
value = coerce(resource, value) if value.is_a?(DelayedEvaluator)
|
54
|
-
value
|
49
|
+
coerce_proc(resource, options[:coerce], *args, **kwargs, &blk)
|
55
50
|
elsif args.length == 1 && kwargs.empty?
|
56
51
|
args[0]
|
57
52
|
else
|
@@ -59,6 +54,19 @@ class Chef
|
|
59
54
|
end
|
60
55
|
end
|
61
56
|
|
57
|
+
def coerce_class(clazz, *args, **kwargs, &blk)
|
58
|
+
value = clazz.new(*args, **kwargs)
|
59
|
+
value.instance_eval(&blk) if block_given?
|
60
|
+
value
|
61
|
+
end
|
62
|
+
|
63
|
+
def coerce_proc(resource, coerce, *args, **kwargs, &blk)
|
64
|
+
value = resource.instance_exec(*args, **kwargs, &coerce) unless resource.nil?
|
65
|
+
value.instance_eval(&blk) if block_given?
|
66
|
+
value = coerce(resource, value) if value.is_a?(DelayedEvaluator)
|
67
|
+
value
|
68
|
+
end
|
69
|
+
|
62
70
|
def emit_dsl
|
63
71
|
return unless instance_variable_name
|
64
72
|
# Holy shit, this looks evil. But Chef does it the same way so yeah.
|
File without changes
|
@@ -20,6 +20,11 @@ class Chef
|
|
20
20
|
module LWRPInclude
|
21
21
|
module_function
|
22
22
|
|
23
|
+
def try_file(filename)
|
24
|
+
return if File.exist?(filename) && File.readable?(filename)
|
25
|
+
fail IOError, "Cannot open or read #{filename}"
|
26
|
+
end
|
27
|
+
|
23
28
|
def filename_for_record(run_context, cookbook_name, segment, name)
|
24
29
|
name += '.rb' unless name.end_with?('.rb')
|
25
30
|
cookbook_version = run_context.cookbook_collection[cookbook_name]
|
@@ -29,8 +34,7 @@ class Chef
|
|
29
34
|
end
|
30
35
|
|
31
36
|
def build_resource_module_from_file(filename)
|
32
|
-
|
33
|
-
|
37
|
+
try_file(filename)
|
34
38
|
resource_module = Module.new
|
35
39
|
resource_module.instance_variable_set('@filename', filename)
|
36
40
|
def resource_module.included(cls)
|
@@ -43,6 +43,36 @@ EOH
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
module AttributeDSL
|
47
|
+
def namespace(*args, **kwargs, &blk)
|
48
|
+
@namespace_options = namespace_options.merge(kwargs)
|
49
|
+
keys = args.map(&:to_s)
|
50
|
+
@current_namespace = current_namespace + keys
|
51
|
+
instance_eval(&blk) if block_given?
|
52
|
+
@current_namespace = current_namespace - keys
|
53
|
+
@namespace_options = nil if @current_namespace.empty?
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def namespace_options
|
60
|
+
@namespace_options ||= { precedence: default }
|
61
|
+
end
|
62
|
+
|
63
|
+
def current_namespace
|
64
|
+
@current_namespace ||= []
|
65
|
+
end
|
66
|
+
|
67
|
+
def vivified
|
68
|
+
precedence = namespace_options[:precedence]
|
69
|
+
current_namespace.inject(precedence) do |hash, item|
|
70
|
+
hash[item] ||= {}
|
71
|
+
hash[item]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
46
76
|
module DSL
|
47
77
|
def namespace(*args)
|
48
78
|
keys = args.map(&:to_s)
|
@@ -50,36 +80,20 @@ EOH
|
|
50
80
|
yield attribute if block_given?
|
51
81
|
end
|
52
82
|
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class Node
|
56
|
-
def namespace(*args, **kwargs, &blk)
|
57
|
-
@namespace_options ||= { precedence: default }
|
58
|
-
@namespace_options = @namespace_options.merge(kwargs)
|
59
|
-
keys = args.map(&:to_s)
|
60
|
-
@current_namespace ||= []
|
61
|
-
@current_namespace += keys
|
62
|
-
instance_eval(&blk) if block_given?
|
63
|
-
@current_namespace -= keys
|
64
|
-
@namespace_options = nil if @current_namespace.empty?
|
65
|
-
nil
|
66
|
-
end
|
67
83
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
84
|
+
module MonkeyPatches
|
85
|
+
module Node
|
86
|
+
def method_missing(method_name, *args)
|
87
|
+
super
|
88
|
+
rescue NoMethodError
|
89
|
+
if args.empty?
|
90
|
+
deep_key = current_namespace.dup << method_name.to_s
|
91
|
+
return ::Chef::CookieCutter::Namespace.deep_fetch!(attributes, deep_key)
|
92
|
+
else
|
93
|
+
vivified[method_name.to_s] = args.size == 1 ? args.first : args
|
94
|
+
return nil
|
95
|
+
end
|
80
96
|
end
|
81
|
-
vivified[method_name.to_s] = args.size == 1 ? args.first : args
|
82
|
-
return nil
|
83
97
|
end
|
84
98
|
end
|
85
99
|
end
|
@@ -40,17 +40,17 @@ EOH
|
|
40
40
|
|
41
41
|
module DSL
|
42
42
|
def shared?(name)
|
43
|
-
exist_state?(:
|
43
|
+
exist_state?(:cookie_cutter, :shared_blocks, name)
|
44
44
|
end
|
45
45
|
|
46
46
|
def shared(name, &block)
|
47
47
|
fail Chef::CookieCutter::SharedBlocks::SharedBlockAlreadyDefined, name if shared? name
|
48
|
-
store_state(:
|
48
|
+
store_state(:cookie_cutter, :shared_blocks, name, block)
|
49
49
|
end
|
50
50
|
|
51
51
|
def include_shared(name)
|
52
52
|
fail Chef::CookieCutter::SharedBlocks::SharedBlockNotDefined, name unless shared? name
|
53
|
-
block = fetch_state(:
|
53
|
+
block = fetch_state(:cookie_cutter, :shared_blocks, name)
|
54
54
|
instance_eval(&block)
|
55
55
|
end
|
56
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-cookie_cutter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ole Claussen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|
@@ -74,8 +74,8 @@ extra_rdoc_files: []
|
|
74
74
|
files:
|
75
75
|
- lib/chef/cookie_cutter.rb
|
76
76
|
- lib/chef/cookie_cutter/fancy_property.rb
|
77
|
+
- lib/chef/cookie_cutter/lwrp_build_params.rb
|
77
78
|
- lib/chef/cookie_cutter/lwrp_include.rb
|
78
|
-
- lib/chef/cookie_cutter/monkey_patches.rb
|
79
79
|
- lib/chef/cookie_cutter/namespace.rb
|
80
80
|
- lib/chef/cookie_cutter/run_state.rb
|
81
81
|
- lib/chef/cookie_cutter/shared_blocks.rb
|