util-params 0.2.0 → 0.2.1
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/util/params/params.rb +25 -29
- data/lib/util/params/version.rb +1 -1
- 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: 9b76df33dec504afda2e70986287005d449b6434
|
4
|
+
data.tar.gz: b5dc45683e7644e4dd4f3c9f8cc8ef2e956b6a73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bd2337b0a2e3cd6aabe976031c526131026507142a631c66a28555afeb97a801e0a6939819a4e01f7fb8ae55ba15f1eb2e1cdac0666562c4b631b79bc1a9248
|
7
|
+
data.tar.gz: 493578f109393d4489d3f4b5f755f4d42e46bac8dc5afa4b239db6fd98627bd1d63eb3f969d0118c0fd9f718d26db33fd693dfa665afbce85ebacf7d8c249f14
|
data/lib/util/params/params.rb
CHANGED
@@ -10,17 +10,17 @@ module Util
|
|
10
10
|
end
|
11
11
|
|
12
12
|
module Type
|
13
|
-
INTEGER =
|
14
|
-
STRING =
|
15
|
-
FLOAT =
|
16
|
-
FILE =
|
17
|
-
BOOLEAN =
|
18
|
-
OBJECT =
|
19
|
-
ARRAY =
|
13
|
+
INTEGER = :integer
|
14
|
+
STRING = :string
|
15
|
+
FLOAT = :float
|
16
|
+
FILE = :file
|
17
|
+
BOOLEAN = :boolean
|
18
|
+
OBJECT = :object
|
19
|
+
ARRAY = :array
|
20
20
|
end
|
21
21
|
|
22
22
|
def get_params options
|
23
|
-
options =
|
23
|
+
options = options.deep_symbolize_keys
|
24
24
|
|
25
25
|
key = options[:key]
|
26
26
|
val = _load_val params, key, options[:default], options[:require]
|
@@ -73,7 +73,7 @@ module Util
|
|
73
73
|
def _load_val vals, key, default, is_require
|
74
74
|
|
75
75
|
unless vals.has_key? key
|
76
|
-
|
76
|
+
_push_error "#{key.to_s} == nil" if is_require
|
77
77
|
return default
|
78
78
|
end
|
79
79
|
|
@@ -116,7 +116,7 @@ module Util
|
|
116
116
|
return nil if val.blank?
|
117
117
|
|
118
118
|
if /[^\d]/ =~ val.to_s
|
119
|
-
|
119
|
+
_push_error "#{key.to_s} type [#{val.to_s}] != integer"
|
120
120
|
end
|
121
121
|
|
122
122
|
v = val.to_i
|
@@ -125,15 +125,15 @@ module Util
|
|
125
125
|
for e in enum
|
126
126
|
return v if e === v
|
127
127
|
end
|
128
|
-
|
128
|
+
_push_error "#{key.to_s} == unknone val [#{v.to_s}]"
|
129
129
|
end
|
130
130
|
|
131
131
|
if min && (v < min)
|
132
|
-
|
132
|
+
_push_error "#{key.to_s} val [#{v.to_s}] < #{min.to_s}"
|
133
133
|
end
|
134
134
|
|
135
135
|
if max && (v > max)
|
136
|
-
|
136
|
+
_push_error "#{key.to_s} val [#{v.to_s}] > #{max.to_s}"
|
137
137
|
end
|
138
138
|
|
139
139
|
v
|
@@ -148,19 +148,19 @@ module Util
|
|
148
148
|
enum.each do |e|
|
149
149
|
return v if e === v
|
150
150
|
end
|
151
|
-
|
151
|
+
_push_error "#{key.to_s} == unknone val [#{v.to_s}]"
|
152
152
|
end
|
153
153
|
|
154
154
|
if min && (v.length < min)
|
155
|
-
|
155
|
+
_push_error "#{key.to_s}.length < #{min.to_s} ('#{v.to_s}')"
|
156
156
|
end
|
157
157
|
|
158
158
|
if max && (v.length > max)
|
159
|
-
|
159
|
+
_push_error "#{key.to_s}.length > #{max.to_s} ('#{v.to_s}')"
|
160
160
|
end
|
161
161
|
|
162
162
|
if reg && !(/#{reg}/ =~ val)
|
163
|
-
|
163
|
+
_push_error "#{key.to_s} unmatch /#{reg.to_s}/ =~ [#{v.to_s}]"
|
164
164
|
end
|
165
165
|
|
166
166
|
v
|
@@ -170,17 +170,17 @@ module Util
|
|
170
170
|
return nil if val.blank?
|
171
171
|
|
172
172
|
if /[^\d.]/ =~ val
|
173
|
-
|
173
|
+
_push_error "#{key.to_s} type [#{val.to_s}] != float"
|
174
174
|
end
|
175
175
|
|
176
176
|
v = val.to_f
|
177
177
|
|
178
178
|
if min && (v < min)
|
179
|
-
|
179
|
+
_push_error "#{key.to_s} val [#{v.to_s}] < #{min.to_s}"
|
180
180
|
end
|
181
181
|
|
182
182
|
if max && (v > max)
|
183
|
-
|
183
|
+
_push_error "#{key.to_s} val [#{v.to_s}] > #{max.to_s}"
|
184
184
|
end
|
185
185
|
|
186
186
|
v
|
@@ -199,7 +199,7 @@ module Util
|
|
199
199
|
return nil if val.nil?
|
200
200
|
|
201
201
|
if f.size.blank?
|
202
|
-
|
202
|
+
_push_error "#{key.to_s} == nil"
|
203
203
|
return nil
|
204
204
|
end
|
205
205
|
|
@@ -213,18 +213,18 @@ module Util
|
|
213
213
|
return nil if val.nil?
|
214
214
|
|
215
215
|
unless val.kind_of? Array
|
216
|
-
|
216
|
+
_push_error "#{key.to_s}.type != Array"
|
217
217
|
return nil
|
218
218
|
end
|
219
219
|
|
220
220
|
v = val
|
221
221
|
|
222
222
|
if min && (v.length < min)
|
223
|
-
|
223
|
+
_push_error "#{key.to_s} val [#{v.to_s}.length] < #{min.to_s}"
|
224
224
|
end
|
225
225
|
|
226
226
|
if max && (v.length > max)
|
227
|
-
|
227
|
+
_push_error "#{key.to_s} val [#{v.to_s}.length] > #{max.to_s}"
|
228
228
|
end
|
229
229
|
|
230
230
|
v
|
@@ -245,12 +245,8 @@ module Util
|
|
245
245
|
end
|
246
246
|
end
|
247
247
|
|
248
|
-
def _symbolize_keys hash
|
249
|
-
hash.map{|k,v| [k.to_sym, v] }.to_h
|
250
|
-
end
|
251
|
-
|
252
248
|
# エラー追加
|
253
|
-
def
|
249
|
+
def _push_error message
|
254
250
|
@is_error |= true
|
255
251
|
@errors.push message
|
256
252
|
end
|
data/lib/util/params/version.rb
CHANGED