cerulean 0.0.10 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cerulean.rb +21 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2382ebd4159162983fe7030d8a96c3313ef26b49
|
4
|
+
data.tar.gz: 33b78f3973f440a7604ab561babcd416b31d00db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbd2b1d0566dabefd2d138a210b0274e5569f6b96f06d99a68a0da8c7aeb47b7e6d622a86863f11c7aad3a1733f7d78b8ca9897dcb5a35ed9429c982368dd0d4
|
7
|
+
data.tar.gz: a7e2fd1e8e8cb109fdbb2b2525e620a62180f16ce8b4abe500cfdca1064c117ed47081c68fd8617651745a6930d80a4c4ba54bc9e1f6aaf21d1d58e842fb7aed
|
data/lib/cerulean.rb
CHANGED
@@ -37,6 +37,13 @@ class ActionDSL
|
|
37
37
|
end
|
38
38
|
|
39
39
|
module Cerulean
|
40
|
+
class ParamsInvalid < StandardError
|
41
|
+
attr_reader :errors
|
42
|
+
def initialize(errors)
|
43
|
+
@errors = errors
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
40
47
|
def self.included(receiver)
|
41
48
|
receiver.extend(ClassMethods)
|
42
49
|
end
|
@@ -118,38 +125,47 @@ module Cerulean
|
|
118
125
|
|
119
126
|
if meta.has_key?(:params)
|
120
127
|
@declared = {}
|
128
|
+
errors = {}
|
121
129
|
meta[:params].each do |param, opts|
|
122
130
|
if params.has_key?(param.to_s)
|
123
131
|
p = validate_param_type(params[param.to_s], opts[:type])
|
124
132
|
|
125
133
|
if p.nil?
|
126
|
-
|
134
|
+
errors[param] ||= []
|
135
|
+
errors[param] << "#{param.to_s} is not a #{opts[:type].to_s.downcase}"
|
127
136
|
end
|
128
137
|
|
129
138
|
if opts.has_key?(:min)
|
130
139
|
if p < opts[:min]
|
131
|
-
|
140
|
+
errors[param] ||= []
|
141
|
+
errors[param] << "must be greater than or equal to #{opts[:min]}"
|
132
142
|
end
|
133
143
|
end
|
134
144
|
|
135
145
|
if opts.has_key?(:max)
|
136
146
|
if p > opts[:max]
|
137
|
-
|
147
|
+
errors[param] ||= []
|
148
|
+
errors[param] << "must be less than or equal to #{opts[:max]}"
|
138
149
|
end
|
139
150
|
end
|
140
151
|
|
141
152
|
if opts.has_key?(:values)
|
142
153
|
unless opts[:values].map { |val| val.to_s }.include?(p.to_s)
|
143
|
-
|
154
|
+
errors[param] ||= []
|
155
|
+
errors[param] << "must be one of #{opts[:values]}"
|
144
156
|
end
|
145
157
|
end
|
146
158
|
|
147
159
|
@declared[param] = p
|
148
160
|
else
|
149
161
|
params[param] = opts[:default] if opts.has_key?(:default)
|
150
|
-
|
162
|
+
if opts[:required]
|
163
|
+
errors[param] ||= []
|
164
|
+
errors[param] << "is required"
|
165
|
+
end
|
151
166
|
end
|
152
167
|
end
|
168
|
+
raise ParamsInvalid.new(errors) if errors.keys.any?
|
153
169
|
end
|
154
170
|
end
|
155
171
|
end
|