chef-validation 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d0e9b458060b1ff05e0351dd1d96917b6f3d5a8
4
- data.tar.gz: 4806e2f4670ad28454893828cc904c5610074c10
3
+ metadata.gz: 31e958e3ea66a331de897e17a49aa5c1f3c03a45
4
+ data.tar.gz: 492e81c01dbe899d9f719460ec82276a9b39fef2
5
5
  SHA512:
6
- metadata.gz: 261ea5766065f68152e7b11a7975b2b0a6f4b2c644ddf449198bed3a93607c6961d6865046d315256ddc7e81a1392ea779bba38817a30efeae30c49a2f95fb15
7
- data.tar.gz: 453e514792b2f9b588779881a1e9441307664027abe811ebf8672a48647296bbce91b0dba9ac500b55a5c7288e58a695fe59b1cd9ecd94d9133a67038e1b36bd
6
+ metadata.gz: c568fcf74d48cdb537fe658f27e8fd5bd00c11d60f4583e621ffdb6cd4761f0df3e2eec8459444fd488f9c1734ce4e4626051a30753c9ce8bda3082db440db4f
7
+ data.tar.gz: e4944d735b32db312b5aea8be505d1896dda5b9a16e62f1c5200986586d66d16cb36bc0b22537346dfb3a352f7d92a029564e985e062793c9738d02b9a4056f1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.1.4
2
+
3
+ * Bug Fixes
4
+ * Fix issue with validating non-string required attributes
5
+
1
6
  # 0.1.3
2
7
 
3
8
  * Bug Fixes
@@ -1,2 +1,3 @@
1
1
  require_relative "ext/context"
2
2
  require_relative "ext/hash"
3
+ require_relative "ext/object"
@@ -0,0 +1,150 @@
1
+ # Copyright (c) 2005-2014 David Heinemeier Hansson
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Object
23
+ # An object is blank if it's false, empty, or a whitespace string.
24
+ # For example, '', ' ', +nil+, [], and {} are all blank.
25
+ #
26
+ # This simplifies
27
+ #
28
+ # address.nil? || address.empty?
29
+ #
30
+ # to
31
+ #
32
+ # address.blank?
33
+ #
34
+ # @return [true, false]
35
+ def blank?
36
+ respond_to?(:empty?) ? !!empty? : !self
37
+ end
38
+
39
+ # An object is present if it's not blank.
40
+ #
41
+ # @return [true, false]
42
+ def present?
43
+ !blank?
44
+ end
45
+
46
+ # Returns the receiver if it's present otherwise returns +nil+.
47
+ # <tt>object.presence</tt> is equivalent to
48
+ #
49
+ # object.present? ? object : nil
50
+ #
51
+ # For example, something like
52
+ #
53
+ # state = params[:state] if params[:state].present?
54
+ # country = params[:country] if params[:country].present?
55
+ # region = state || country || 'US'
56
+ #
57
+ # becomes
58
+ #
59
+ # region = params[:state].presence || params[:country].presence || 'US'
60
+ #
61
+ # @return [Object]
62
+ def presence
63
+ self if present?
64
+ end
65
+ end
66
+
67
+ class NilClass
68
+ # +nil+ is blank:
69
+ #
70
+ # nil.blank? # => true
71
+ #
72
+ # @return [true]
73
+ def blank?
74
+ true
75
+ end
76
+ end
77
+
78
+ class FalseClass
79
+ # +false+ is blank:
80
+ #
81
+ # false.blank? # => true
82
+ #
83
+ # @return [true]
84
+ def blank?
85
+ true
86
+ end
87
+ end
88
+
89
+ class TrueClass
90
+ # +true+ is not blank:
91
+ #
92
+ # true.blank? # => false
93
+ #
94
+ # @return [false]
95
+ def blank?
96
+ false
97
+ end
98
+ end
99
+
100
+ class Array
101
+ # An array is blank if it's empty:
102
+ #
103
+ # [].blank? # => true
104
+ # [1,2,3].blank? # => false
105
+ #
106
+ # @return [true, false]
107
+ alias_method :blank?, :empty?
108
+ end
109
+
110
+ class Hash
111
+ # A hash is blank if it's empty:
112
+ #
113
+ # {}.blank? # => true
114
+ # { key: 'value' }.blank? # => false
115
+ #
116
+ # @return [true, false]
117
+ alias_method :blank?, :empty?
118
+ end
119
+
120
+ class String
121
+ BLANK_RE = /\A[[:space:]]*\z/
122
+
123
+ # A string is blank if it's empty or contains whitespaces only:
124
+ #
125
+ # ''.blank? # => true
126
+ # ' '.blank? # => true
127
+ # "\t\n\r".blank? # => true
128
+ # ' blah '.blank? # => false
129
+ #
130
+ # Unicode whitespace is supported:
131
+ #
132
+ # "\u00a0".blank? # => true
133
+ #
134
+ # @return [true, false]
135
+ def blank?
136
+ BLANK_RE === self
137
+ end
138
+ end
139
+
140
+ class Numeric #:nodoc:
141
+ # No number is blank:
142
+ #
143
+ # 1.blank? # => false
144
+ # 0.blank? # => false
145
+ #
146
+ # @return [false]
147
+ def blank?
148
+ false
149
+ end
150
+ end
@@ -37,13 +37,13 @@ module Chef::Validation
37
37
  value = HashExt.dig(node.attributes, name, ATTR_SEPARATOR)
38
38
  errors = []
39
39
 
40
- if (rules["required"] == "required" || rules["required"] == true)
40
+ if rules["required"].present?
41
41
  errors += validate_required(value, name)
42
42
  end
43
- unless rules["type"].nil?
43
+ if rules["type"].present?
44
44
  errors += validate_type(value, rules["type"], name)
45
45
  end
46
- unless rules["choice"].nil? || rules["choice"].empty?
46
+ if rules["choice"].present?
47
47
  errors += validate_choice(value, rules["choice"], name)
48
48
  end
49
49
 
@@ -70,7 +70,7 @@ module Chef::Validation
70
70
 
71
71
  def validate_required(value, name)
72
72
  errors = []
73
- if value.nil? || value.empty?
73
+ if value.present?
74
74
  errors << "Required attribute but was not present."
75
75
  end
76
76
  errors
@@ -1,4 +1,4 @@
1
1
  class Chef; end;
2
2
  module Chef::Validation
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -76,6 +76,7 @@ files:
76
76
  - lib/chef/validation/ext.rb
77
77
  - lib/chef/validation/ext/context.rb
78
78
  - lib/chef/validation/ext/hash.rb
79
+ - lib/chef/validation/ext/object.rb
79
80
  - lib/chef/validation/formatter.rb
80
81
  - lib/chef/validation/validator.rb
81
82
  - lib/chef/validation/version.rb