ratatouille 1.2.5 → 1.2.6

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.
data/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ ## 1.2.6
2
+
3
+ * CHANGELOG added
4
+ * required\_key logic moved to given\_key and triggered with a :required => true option
5
+ * required\_key now calls given_key with :required => true
6
+
7
+ ## 1.2.5
8
+
9
+ * required\_key fixed so that block behaves like given\_key block, by diving into the context of the key value
10
+
11
+ ## 1.2.4
12
+
13
+ * required\_key added to HashMethods
14
+ * Additional Tests
15
+
16
+ ## 1.2.2
17
+
18
+ * is\_a? method added to HashMethods
19
+ * Additional Tests
20
+
21
+ ## 1.2.0
22
+
23
+ * Added Ratatouille::Ratifier name attribute for use with dynamically changing scoped errors.
24
+ * The current Ratifier name (in scope of the validation block) will be appended to errors created
25
+ in the direct context of that block.
26
+ * The name attribute is automatically set when using a given_key block. However, you may pass a :name
27
+ option to the given\_key method to manually set it.
28
+
29
+ ## 1.1.1
30
+
31
+ * choice\_of validation errors show semantically correct key names (Symbols, Strings, etc.)
32
+ * choice\_of tweaked/fixed to perform proper validation on list of keys
33
+
34
+ ## 1.0.0
35
+
36
+ * Not to be mistaken by 0.1.0
37
+ * Plethora of tests added
38
+ * Refactoring Code
39
+ * Organization and Documentation
40
+
41
+ ## 0.9.2
42
+
43
+ * Initial Release
44
+ * Strange, I know, but this library was being production tested prior to becoming a gem.
@@ -9,6 +9,13 @@ module Ratatouille
9
9
  def given_key(key, options={}, &block)
10
10
  options[:name] = options.fetch(:name, (Symbol === key ? ":#{key}" : key.to_s) )
11
11
 
12
+ if options.fetch(:required, false) == true
13
+ unless @ratifiable_object.has_key?(key)
14
+ validation_error("Missing key #{key.inspect}")
15
+ return
16
+ end
17
+ end
18
+
12
19
  if @ratifiable_object.has_key?(key) && block_given?
13
20
  child_object = Ratatouille::Ratifier.new(@ratifiable_object[key], options, &block)
14
21
  @errors[key] = child_object.errors unless child_object.valid?
@@ -64,12 +71,7 @@ module Ratatouille
64
71
 
65
72
  unless common_keys.size == req_keys.size
66
73
  (req_keys - common_keys).each do |missed|
67
- case missed
68
- when Symbol then validation_error("Missing :#{missed}")
69
- when String then validation_error("Missing #{missed}")
70
- when respond_to?(:to_s)
71
- validation_error("Missing #{missed.to_s}")
72
- end
74
+ validation_error("Missing #{missed.inspect}")
73
75
  end
74
76
  return
75
77
  end
@@ -83,25 +85,12 @@ module Ratatouille
83
85
  # Perform validation on a key that must be present in the Hash to validate. Otherwise,
84
86
  # an error will be added.
85
87
  #
86
- # @param [String,Symbol] req_key Required Key
88
+ # @param key Required Key
87
89
  # @return [void]
88
- def required_key(req_key, options={}, &block)
89
- if req_key.nil?
90
- validation_error("required_key needs key argument")
91
- return
92
- end
93
-
94
- unless @ratifiable_object.has_key?(req_key)
95
- case req_key
96
- when Symbol then validation_error("Missing key :#{req_key}")
97
- when String then validation_error("Missing key #{req_key}")
98
- when respond_to?(:to_s)
99
- validation_error("Missing key #{req_key.to_s}")
100
- end
101
- return
102
- end
103
-
104
- given_key(req_key, options, &block) if block_given?
90
+ def required_key(key, options={}, &block)
91
+ options[:required] = true
92
+ # Pass on processing to given_key with :required => true option
93
+ given_key(key, options, &block)
105
94
  rescue Exception => e
106
95
  validation_error("#{e.message}")
107
96
  end
@@ -1,4 +1,4 @@
1
1
  module Ratatouille
2
2
  # Gem Version
3
- VERSION = "1.2.5"
3
+ VERSION = "1.2.6"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratatouille
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 5
10
- version: 1.2.5
9
+ - 6
10
+ version: 1.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Johnson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-15 00:00:00 Z
18
+ date: 2012-04-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -60,6 +60,7 @@ files:
60
60
  - .gitignore
61
61
  - .travis-yml
62
62
  - .yardopts
63
+ - CHANGELOG.md
63
64
  - Gemfile
64
65
  - LICENSE
65
66
  - README.md