apidiesel 0.8 → 0.9
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 +4 -4
- data/lib/apidiesel/dsl.rb +27 -1
- data/lib/apidiesel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe3d16b8a91f4bd35deafce8149466d3815f4990
|
4
|
+
data.tar.gz: 20f22493471da55fb45c76931ec9a2feb24a8c46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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?
|
data/lib/apidiesel/version.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|