chef-validation 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43bb3f5ee8406de411d11b31cc4b148aa4899118
4
- data.tar.gz: 5ec4d711b379051bf9f5987669c204d7f1e3eab3
3
+ metadata.gz: 9d0e9b458060b1ff05e0351dd1d96917b6f3d5a8
4
+ data.tar.gz: 4806e2f4670ad28454893828cc904c5610074c10
5
5
  SHA512:
6
- metadata.gz: cd65caeecaa338033f74e94e1406068eac8ee4c8c9d1f5a63aa3a242b1451074db4c2534162f5c6d8909a223b22497f59af6171ff5a49613dc472a11314e7cdd
7
- data.tar.gz: 06e603af388bd7cd1574f026d64aeda8270b2d4d85336c3b8b00566e7b492fcf387851468c72d191687226a36d20b362094bf11598c3505710a223deffefe8d7
6
+ metadata.gz: 261ea5766065f68152e7b11a7975b2b0a6f4b2c644ddf449198bed3a93607c6961d6865046d315256ddc7e81a1392ea779bba38817a30efeae30c49a2f95fb15
7
+ data.tar.gz: 453e514792b2f9b588779881a1e9441307664027abe811ebf8672a48647296bbce91b0dba9ac500b55a5c7288e58a695fe59b1cd9ecd94d9133a67038e1b36bd
@@ -1,3 +1,9 @@
1
+ # 0.1.3
2
+
3
+ * Bug Fixes
4
+ * Fix issue on some versions of Chef where metadata would not be properly loaded at different points of the Chef run
5
+ * Fix crash when a value is `nil` and checking for it's presence
6
+
1
7
  # 0.1.2
2
8
 
3
9
  * Enhancements
@@ -39,9 +39,17 @@ module Chef::Validation
39
39
 
40
40
  private
41
41
 
42
+ # It's quite sad, but metadata is not guaranteed to be 100% loaded depending on the
43
+ # version of Chef you are using and at which point of the Chef Client run you are at.
44
+ def reload_metadata(cookbook)
45
+ file = cookbook.root_filenames.find { |x| File.basename(x) == "metadata.json" }
46
+ cookbook.metadata.from_json(IO.read(file))
47
+ end
48
+
42
49
  def validate_all(node)
43
50
  total_errors = {}
44
51
  ContextExt.cookbooks(node.run_context).each do |cookbook|
52
+ reload_metadata(cookbook)
45
53
  unless (errors = Validator.run(node, cookbook.metadata)).empty?
46
54
  total_errors[cookbook.name] = errors
47
55
  end
@@ -54,6 +62,7 @@ module Chef::Validation
54
62
  unless cookbook = ContextExt.cookbook(node.run_context, name)
55
63
  raise "Cookbook not found: #{cookbook}"
56
64
  end
65
+ reload_metadata(cookbook)
57
66
  unless (errors = Validator.run(node, cookbook.metadata)).empty?
58
67
  total_errors[cookbook.name] = errors
59
68
  end
@@ -60,22 +60,25 @@ module Chef::Validation
60
60
  BOOLEAN = "boolean".freeze
61
61
  NUMERIC = "numeric".freeze
62
62
 
63
- def validate_choice(value, choices, name, errors = [])
63
+ def validate_choice(value, choices, name)
64
+ errors = []
64
65
  unless choices.include?(value)
65
66
  errors << "Must be one of the following choices: #{choices.join(", ")}."
66
67
  end
67
68
  errors
68
69
  end
69
70
 
70
- def validate_required(value, name, errors = [])
71
- if value.empty? || value.nil?
71
+ def validate_required(value, name)
72
+ errors = []
73
+ if value.nil? || value.empty?
72
74
  errors << "Required attribute but was not present."
73
75
  end
74
76
  errors
75
77
  end
76
78
 
77
- def validate_type(value, type, name, errors = [])
78
- state = nil
79
+ def validate_type(value, type, name)
80
+ errors = []
81
+ state = nil
79
82
  case type.downcase
80
83
  when STRING
81
84
  state = :error unless value.is_a?(String)
@@ -1,4 +1,4 @@
1
1
  class Chef; end;
2
2
  module Chef::Validation
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
11
+ date: 2014-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef