hoodoo 1.12.3 → 1.12.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: 9cd0bbca0d44ff8c52c354e140565325d8447f10
4
- data.tar.gz: 5faa6103ed09143226c2d869069af59c0ea5a76f
3
+ metadata.gz: 612e215b33df39e4942acbf763c27af9c817f5a2
4
+ data.tar.gz: 9159951c875326ec7bcdd5d696365563028c7d2d
5
5
  SHA512:
6
- metadata.gz: b3a8f6e8f61b54b65b9842fffe90aa1e0503fc4678a876ffcdf75de4075792cf8ff1c444bdb9b72c722a9ced24f4916ebfbdff338425c97dbe53c18e153bfd7a
7
- data.tar.gz: 47ff963da7a1ff972fba27090290398bfcd35612d5657df877b3f623c3726dbd8e3fd2ed3668df1a43c6df5e3f5caf6b04ec0489bfd0f3ae441aa7ba387eab42
6
+ metadata.gz: c2c0eeb88c1f8950a3dda6725f1110b8e32b9767c30dfbe4a560c4dbacaaad5d459ccfe71d46de5b850031d459708853aa818cfcc06f241f3176ee4319874403
7
+ data.tar.gz: b747857c2b8469936e728e81872b80d33016df0a68a2e15a6001794593d216a6c86ec6d30cae97d0c48e6f1d9fd22bb947307a8b29cea398a8b3829d886f6a38
@@ -93,8 +93,12 @@ module Hoodoo
93
93
  # &block:: Optional block declaring the fields making up the nested
94
94
  # hash
95
95
  #
96
- # Example 1 - a Hash where keys must be <= 16 characters long and values
97
- # must match the Hoodoo::Data::Types::Currency type.
96
+ # == Example 1
97
+ #
98
+ # A Hash where keys must be <= 16 characters long and values must match
99
+ # a <tt>Hoodoo::Data::Types::Currency</tt> type (with the default
100
+ # Hoodoo::Data::Types namespace use arising from the Symbol passed
101
+ # to the #type method).
98
102
  #
99
103
  # class CurrencyHash < Hoodoo::Presenters::Base
100
104
  # schema do
@@ -108,14 +112,19 @@ module Hoodoo
108
112
  #
109
113
  # See Hoodoo::Presenters::Hash#keys for more information and examples.
110
114
  #
111
- # Example 2 - a Hash where keys must be 'one' or 'two', each with a
112
- # value matching the given schema.
115
+ # == Example 2
116
+ #
117
+ # A Hash where keys must be 'one' or 'two', each with a value matching
118
+ # the given schema. Here, the example assumes that a subclass of
119
+ # Hoodoo::Presenters::Base has been defined under the name of
120
+ # <tt>SomeNamespace::Types::Currency</tt>, since this is passed as a
121
+ # class reference to the #type method.
113
122
  #
114
123
  # class AltCurrencyHash < Hoodoo::Presenters::Base
115
124
  # schema do
116
125
  # hash :currencies do
117
126
  # key :one do
118
- # type :Currency
127
+ # type SomeNamespace::Types::Currency
119
128
  # end
120
129
  #
121
130
  # key :two do
@@ -128,6 +137,69 @@ module Hoodoo
128
137
  #
129
138
  # See Hoodoo::Presenters::Hash#key for more information and examples.
130
139
  #
140
+ # == Limitations
141
+ #
142
+ # The syntax cannot express simple value types. It always describes a
143
+ # nested object. So, the following describes a Hash called +payload+
144
+ # which has arbitrary keys each leading to a nested _object_ with
145
+ # key/value pairs where the key is called +some_value+ and the value
146
+ # is an arbitrary length String:
147
+ #
148
+ # class NotSoSimpleHash < Hoodoo::Presenters::Base
149
+ # schema do
150
+ # hash :payload do
151
+ # keys do
152
+ # text :some_value
153
+ # end
154
+ # end
155
+ # end
156
+ # end
157
+ #
158
+ # This is a valid piece of Ruby input data for the above which will
159
+ # render without changes and validate successfully:
160
+ #
161
+ # data = {
162
+ # "payload" => {
163
+ # "any_key_name" => { "some_value" => "Any string" },
164
+ # "another_key_name" => { "some_value" => "Another string" },
165
+ # }
166
+ # }
167
+ #
168
+ # NotSoSimpleHash.validate( data )
169
+ # # => []
170
+ #
171
+ # This is invalid because one of the values is not a String:
172
+ #
173
+ # data = {
174
+ # "payload" => {
175
+ # "any_key_name" => { "some_value" => "Any string" },
176
+ # "another_key_name" => { "some_value" => 22 },
177
+ # }
178
+ # }
179
+ #
180
+ # NotSoSimpleHash.validate( data )
181
+ # # => [{"code"=>"generic.invalid_string",
182
+ # # "message"=>"Field `payload.another_key_name.some_value` is an invalid string",
183
+ # # "reference"=>"payload.another_key_name.some_value"}]
184
+ #
185
+ # This is invalid because the DSL cannot express a simple String value
186
+ # for the keys:
187
+ #
188
+ # data = {
189
+ # "payload" => {
190
+ # "any_key_name" => "Any string",
191
+ # "another_key_name" => "Another string",
192
+ # }
193
+ # }
194
+ #
195
+ # NotSoSimpleHash.validate( data )
196
+ # # => [{"code"=>"generic.invalid_object",
197
+ # # "message"=>"Field `payload.any_key_name` is an invalid object",
198
+ # # "reference"=>"payload.any_key_name"},
199
+ # # {"code"=>"generic.invalid_object",
200
+ # # "message"=>"Field `payload.another_key_name` is an invalid object",
201
+ # # "reference"=>"payload.another_key_name"}]
202
+ #
131
203
  def hash( name, options = {}, &block )
132
204
  hash = property( name, Hoodoo::Presenters::Hash, options, &block )
133
205
  internationalised() if hash.is_internationalised?()
@@ -283,7 +355,7 @@ module Hoodoo
283
355
  # question, e.g. +BasketItem+. The deprecated form of this
284
356
  # interface takes the name of the type to nest as a symbol,
285
357
  # e.g. +:BasketItem+, in which case the Type must be
286
- # declared within nested modules "Hoodoo::Data::Types".
358
+ # declared within nested modules Hoodoo::Data::Types.
287
359
  #
288
360
  # +options+:: Optional options hash. No options currently defined.
289
361
  #
@@ -403,7 +475,7 @@ module Hoodoo
403
475
  # form of this interface takes the name of the type to
404
476
  # nest as a symbol, e.g. +:Product+, in which case the
405
477
  # Resource must be declared within nested modules
406
- # "Hoodoo::Data::Types".
478
+ # Hoodoo::Data::Types.
407
479
  #
408
480
  # +options+:: Optional options hash. No options currently defined.
409
481
  #
@@ -84,8 +84,8 @@ module Hoodoo
84
84
  # a block is given, use Hoodoo::Presenters::BaseDSL to describe how any
85
85
  # of the values in the Hash must look.
86
86
  #
87
- # +options+:: A +Hash+ of options - currently only +:length => [n]+ is
88
- # supported, which describes the maximum permitted length of
87
+ # +options+:: A +Hash+ of options; currently only <tt>:length => [n]</tt>
88
+ # is supported, describing the maximum permitted length of
89
89
  # the key. If this option is omitted, keys can be any length.
90
90
  #
91
91
  # Example:
@@ -1,5 +1,5 @@
1
1
  ########################################################################
2
- # File:: service_middleware.rb
2
+ # File:: middleware.rb
3
3
  # (C):: Loyalty New Zealand 2014
4
4
  #
5
5
  # Purpose:: Rack middleware, declared in a +config.ru+ file in the usual
@@ -12,6 +12,6 @@ module Hoodoo
12
12
  # The Hoodoo gem version. If this changes, ensure that the date in
13
13
  # "hoodoo.gemspec" is correct and run "bundle install" (or "update").
14
14
  #
15
- VERSION = '1.12.3'
15
+ VERSION = '1.12.4'
16
16
 
17
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoodoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.3
4
+ version: 1.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loyalty New Zealand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2017-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kgio