cerulean 0.0.10 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cerulean.rb +21 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 955c05a76bb69b3b7d9771eb31afd8cc94d90f84
4
- data.tar.gz: 6e2b6d801ff24d8fcf9b5e76f28714dd8ea47a49
3
+ metadata.gz: 2382ebd4159162983fe7030d8a96c3313ef26b49
4
+ data.tar.gz: 33b78f3973f440a7604ab561babcd416b31d00db
5
5
  SHA512:
6
- metadata.gz: 9e65d60ea860ddadfdffe8a5e4a96eca8b9882e1725cf0d03d2126ab4d7c5c201f45e1835798fc711726154de2adcf55c56f4cfe10e3d00cfa541031056e5f30
7
- data.tar.gz: 887f39fe48f7897df1687ee7835ed2f1c64b2360585a183157fefba50a989e537dff05afd495c2504c66e95858caac00f716d6d21dddd1b15902593b2d4da5a5
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
- raise "#{param} is not a #{opts[:type]}"
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
- raise "#{param} must be greater than or equal to #{opts[:min]}"
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
- raise "#{param} must be less than or equal to #{opts[:max]}"
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
- raise "#{param} must be one of #{opts[:values]}"
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
- raise "#{param} is required" if opts[:required]
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cerulean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Kestell