apidiesel 0.8 → 0.9

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: 99168d8b1698ce3a3154178081267af94fa768ef
4
- data.tar.gz: 74e74db6ff6721aeef9966eb629d79961564dabe
3
+ metadata.gz: fe3d16b8a91f4bd35deafce8149466d3815f4990
4
+ data.tar.gz: 20f22493471da55fb45c76931ec9a2feb24a8c46
5
5
  SHA512:
6
- metadata.gz: cc11532fbc03e1e71dee627e6b72fc0b8fbcc2c601b48fae335a62d672ee06d880790f4164c422a01d8f0837c4c56b13c786c40a2a8a4ac1b489b0c06cc0cb90
7
- data.tar.gz: a4bd9177d8fb13a31ffc7983cad005c6a9a9ead3464ecf316ef6c916e3b53cf13aed6c2d1f09e905abd24edf7b3a434f981b1e7fde5b704ca9871de3d066fb08
6
+ metadata.gz: 9bc4ad1cacf4576f0eaa195c7bf52553bb80cb8d5b897a2dc6c93c027dac01295f7665da3e15e2706902256708aff69935335f7f7eca76b50a218e2bbb5744ea
7
+ data.tar.gz: 86d14c91e1e8ff1b8db828ce61cbc7c38aa60d02672eb6e7035fc4d372b66789c5b859f278d22514e12d6f78e6e54fc3d1d7aeb05ac16866bbe73967e9ac6f7d
data/lib/apidiesel/dsl.rb CHANGED
@@ -136,6 +136,27 @@ module Apidiesel
136
136
  alias_method :time, :datetime
137
137
  alias_method :date, :datetime
138
138
 
139
+ # Defines an object parameter
140
+ #
141
+ #
142
+ # @example
143
+ # expects do
144
+ # object :contract, klass: Contract
145
+ # end
146
+ #
147
+ # @param (see #string)
148
+ # @option *args [Class] :klass
149
+ # @option (see #string)
150
+ def object(param_name, **args)
151
+ type_check = ->(value, param_name) {
152
+ unless value.is_a?(args[:klass])
153
+ raise Apidiesel::InputError, "arg #{param_name} must be a #{args[:klass].name}"
154
+ end
155
+ }
156
+
157
+ validation_builder(type_check, param_name, **args)
158
+ end
159
+
139
160
  protected
140
161
 
141
162
  def validation_builder(duck_typing_check, param_name, *args)
@@ -156,7 +177,12 @@ module Apidiesel
156
177
 
157
178
  unless options.has_key?(:optional) && options[:optional] == true
158
179
  raise Apidiesel::InputError, "missing arg: #{param_name} - options: #{options.inspect}" unless given_params.has_key?(param_name) && !given_params[param_name].nil?
159
- raise Apidiesel::InputError, "invalid arg #{param_name}: must respond to #{duck_typing_check}" unless given_params[param_name].respond_to?(duck_typing_check)
180
+
181
+ if duck_typing_check.is_a?(Proc)
182
+ duck_typing_check.call(given_params[param_name], param_name)
183
+ else
184
+ raise Apidiesel::InputError, "invalid arg #{param_name}: must respond to #{duck_typing_check}" unless given_params[param_name].respond_to?(duck_typing_check)
185
+ end
160
186
  end
161
187
 
162
188
  if options.has_key?(:allowed_values) && !given_params[param_name].blank?
@@ -1,3 +1,3 @@
1
1
  module Apidiesel
2
- VERSION = "0.8"
2
+ VERSION = "0.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apidiesel
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.8'
4
+ version: '0.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan-Christian Foeh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-24 00:00:00.000000000 Z
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport