util-params 0.2.0 → 0.2.1

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: 0fd1ab494a27202fc9796355ecaebcf9b9c67943
4
- data.tar.gz: 496d08fbd05d12cd70a112f4c73bf2f214f55b12
3
+ metadata.gz: 9b76df33dec504afda2e70986287005d449b6434
4
+ data.tar.gz: b5dc45683e7644e4dd4f3c9f8cc8ef2e956b6a73
5
5
  SHA512:
6
- metadata.gz: 4a6749be2796880c8e1698d23171f560cb9e3cfdfc8f7d84202e627a84a99d1d0c911c3f69f469a69b224709838aaec1b492ba80dd5f852eb607c94efa304e1d
7
- data.tar.gz: 0f1a24934ac17c7854d8165fc5be1107309a28afee87a412495f4512425f107bc58ea8c56219adf0fbea23de3e3897f9138de13cfb37fa8c1f50829baf4fe931
6
+ metadata.gz: 9bd2337b0a2e3cd6aabe976031c526131026507142a631c66a28555afeb97a801e0a6939819a4e01f7fb8ae55ba15f1eb2e1cdac0666562c4b631b79bc1a9248
7
+ data.tar.gz: 493578f109393d4489d3f4b5f755f4d42e46bac8dc5afa4b239db6fd98627bd1d63eb3f969d0118c0fd9f718d26db33fd693dfa665afbce85ebacf7d8c249f14
@@ -10,17 +10,17 @@ module Util
10
10
  end
11
11
 
12
12
  module Type
13
- INTEGER = 1
14
- STRING = 2
15
- FLOAT = 3
16
- FILE = 4
17
- BOOLEAN = 5
18
- OBJECT = 6
19
- ARRAY = 7
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 = _symbolize_keys 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
- push_error "#{key.to_s} == nil" if is_require
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
- push_error "#{key.to_s} type [#{val.to_s}] != integer"
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
- push_error "#{key.to_s} == unknone val [#{v.to_s}]"
128
+ _push_error "#{key.to_s} == unknone val [#{v.to_s}]"
129
129
  end
130
130
 
131
131
  if min && (v < min)
132
- push_error "#{key.to_s} val [#{v.to_s}] < #{min.to_s}"
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
- push_error "#{key.to_s} val [#{v.to_s}] > #{max.to_s}"
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
- push_error "#{key.to_s} == unknone val [#{v.to_s}]"
151
+ _push_error "#{key.to_s} == unknone val [#{v.to_s}]"
152
152
  end
153
153
 
154
154
  if min && (v.length < min)
155
- push_error "#{key.to_s}.length < #{min.to_s} ('#{v.to_s}')"
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
- push_error "#{key.to_s}.length > #{max.to_s} ('#{v.to_s}')"
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
- push_error "#{key.to_s} unmatch /#{reg.to_s}/ =~ [#{v.to_s}]"
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
- push_error "#{key.to_s} type [#{val.to_s}] != float"
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
- push_error "#{key.to_s} val [#{v.to_s}] < #{min.to_s}"
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
- push_error "#{key.to_s} val [#{v.to_s}] > #{max.to_s}"
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
- push_error "#{key.to_s} == nil"
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
- push_error "#{key.to_s}.type != Array"
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
- push_error "#{key.to_s} val [#{v.to_s}.length] < #{min.to_s}"
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
- push_error "#{key.to_s} val [#{v.to_s}.length] > #{max.to_s}"
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 push_error message
249
+ def _push_error message
254
250
  @is_error |= true
255
251
  @errors.push message
256
252
  end
@@ -1,5 +1,5 @@
1
1
  module Util
2
2
  module Params
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: util-params
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - unchi