evnt 2.1.5 → 3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/evnt/command.rb +8 -2
- data/lib/evnt/validator.rb +71 -42
- data/lib/evnt/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: ef2fa95d09eb421d9912263783747d85451a4d5e
|
4
|
+
data.tar.gz: af36eef1ef9d3c940e68c2eb6ee0b35b3212964c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d40c2f8c4e51b0d505911f3059da2b2f4d4ade398131f20c38797da2e1f4ad370858b9dcf3843521ae91529ed0331cdf4a47fd6a6b2137a3751a5cd486bb5d61
|
7
|
+
data.tar.gz: ada5ce42640430d0f38c4773461be4edb5a012c64b20253e6a12a76cd3b0d5d47835100078e2645cfb2fd98d37c620e172cf44a53da1a3abdbddbffdea0d1728
|
data/lib/evnt/command.rb
CHANGED
@@ -118,7 +118,7 @@ module Evnt
|
|
118
118
|
}
|
119
119
|
|
120
120
|
# set other data
|
121
|
-
@params = params
|
121
|
+
@params = params
|
122
122
|
end
|
123
123
|
|
124
124
|
# This function calls requested steps (callback) for the command.
|
@@ -132,13 +132,19 @@ module Evnt
|
|
132
132
|
# This function validates the single parameters sets with the "validates" method.
|
133
133
|
def _validate_single_params
|
134
134
|
return if self.class._validations.nil? || self.class._validations.empty?
|
135
|
+
|
135
136
|
self.class._validations.each do |val|
|
136
137
|
result = Evnt::Validator.validates(params[val[:param]], val[:options])
|
137
|
-
|
138
|
+
|
139
|
+
if result == :ERROR
|
138
140
|
err "#{val[:param].capitalize} value not accepted"
|
139
141
|
break
|
142
|
+
else
|
143
|
+
@params[val[:param]] = result
|
140
144
|
end
|
141
145
|
end
|
146
|
+
|
147
|
+
@params.freeze
|
142
148
|
end
|
143
149
|
|
144
150
|
# Class functions:
|
data/lib/evnt/validator.rb
CHANGED
@@ -27,14 +27,16 @@ module Evnt
|
|
27
27
|
# * +presence+ - Boolean value used to tells if the presence is required.
|
28
28
|
##
|
29
29
|
def validates(param, options)
|
30
|
+
result = param
|
30
31
|
options.each do |key, value|
|
31
|
-
|
32
|
+
result = validate_option(result, key, value)
|
33
|
+
break if result == :ERROR
|
32
34
|
end
|
33
35
|
|
34
|
-
|
36
|
+
result
|
35
37
|
rescue StandardError => e
|
36
38
|
puts e
|
37
|
-
|
39
|
+
:ERROR
|
38
40
|
end
|
39
41
|
|
40
42
|
##
|
@@ -54,14 +56,12 @@ module Evnt
|
|
54
56
|
validate_presence(param, option_value)
|
55
57
|
when :blank
|
56
58
|
validate_blank(param, option_value)
|
57
|
-
when :numeric
|
58
|
-
validate_numeric(param, option_value)
|
59
59
|
else
|
60
60
|
raise 'Validator option not accepted'
|
61
61
|
end
|
62
62
|
rescue StandardError => e
|
63
63
|
puts e
|
64
|
-
|
64
|
+
:ERROR
|
65
65
|
end
|
66
66
|
|
67
67
|
##
|
@@ -73,7 +73,7 @@ module Evnt
|
|
73
73
|
# * +value+ - The value of the type option that should be used.
|
74
74
|
##
|
75
75
|
def validate_type(param, value)
|
76
|
-
return
|
76
|
+
return param if param.nil?
|
77
77
|
|
78
78
|
if value.instance_of?(Symbol)
|
79
79
|
validate_type_general(param, value)
|
@@ -84,7 +84,7 @@ module Evnt
|
|
84
84
|
end
|
85
85
|
rescue StandardError => e
|
86
86
|
puts e
|
87
|
-
|
87
|
+
:ERROR
|
88
88
|
end
|
89
89
|
|
90
90
|
##
|
@@ -98,10 +98,13 @@ module Evnt
|
|
98
98
|
##
|
99
99
|
def validate_presence(param, value)
|
100
100
|
is_nil = param.nil?
|
101
|
-
value ? !is_nil : is_nil
|
101
|
+
result = value ? !is_nil : is_nil
|
102
|
+
return param if result
|
103
|
+
|
104
|
+
:ERROR
|
102
105
|
rescue StandardError => e
|
103
106
|
puts e
|
104
|
-
|
107
|
+
:ERROR
|
105
108
|
end
|
106
109
|
|
107
110
|
##
|
@@ -115,25 +118,13 @@ module Evnt
|
|
115
118
|
##
|
116
119
|
def validate_blank(param, value)
|
117
120
|
blank = (!param || param.empty?)
|
118
|
-
value ? blank : !blank
|
119
|
-
|
120
|
-
puts e
|
121
|
-
false
|
122
|
-
end
|
121
|
+
result = value ? blank : !blank
|
122
|
+
return param if result
|
123
123
|
|
124
|
-
|
125
|
-
# This function validates some numeric options for the parameter.
|
126
|
-
#
|
127
|
-
# ==== Attributes
|
128
|
-
#
|
129
|
-
# * +param+ - The parameter to be validated.
|
130
|
-
# * +value+ - The value object with validation specs.
|
131
|
-
##
|
132
|
-
def validate_numeric(param, value)
|
133
|
-
# TODO: Continue
|
124
|
+
:ERROR
|
134
125
|
rescue StandardError => e
|
135
126
|
puts e
|
136
|
-
|
127
|
+
:ERROR
|
137
128
|
end
|
138
129
|
|
139
130
|
# Private functions:
|
@@ -163,6 +154,8 @@ module Evnt
|
|
163
154
|
validates_type_array(param)
|
164
155
|
when :date
|
165
156
|
validates_type_date(param)
|
157
|
+
when :datetime
|
158
|
+
validates_type_datetime(param)
|
166
159
|
else
|
167
160
|
raise 'Validator type option not accepted'
|
168
161
|
end
|
@@ -170,39 +163,75 @@ module Evnt
|
|
170
163
|
|
171
164
|
# This function validates a param type for custom types.
|
172
165
|
def validate_type_custom(param, value)
|
173
|
-
param.instance_of?(Object.const_get(value))
|
166
|
+
return param if param.instance_of?(Object.const_get(value))
|
167
|
+
:ERROR
|
174
168
|
end
|
175
169
|
|
176
|
-
def
|
177
|
-
param
|
170
|
+
def validate_type_symbol(param)
|
171
|
+
return param if param.instance_of?(Symbol)
|
172
|
+
:ERROR
|
178
173
|
end
|
179
174
|
|
180
|
-
def
|
181
|
-
param.instance_of?(
|
175
|
+
def validate_type_boolean(param)
|
176
|
+
return param if param.instance_of?(TrueClass) || param.instance_of?(FalseClass)
|
177
|
+
return true if [1, 'true'].include? param
|
178
|
+
return false if [0, 'false'].include? param
|
179
|
+
:ERROR
|
182
180
|
end
|
183
181
|
|
184
182
|
def validate_type_integer(param)
|
185
|
-
param.instance_of?(Integer)
|
183
|
+
return param if param.instance_of?(Integer)
|
184
|
+
begin
|
185
|
+
return param.to_i
|
186
|
+
rescue StandardError
|
187
|
+
return :ERROR
|
188
|
+
end
|
186
189
|
end
|
187
190
|
|
188
|
-
def
|
189
|
-
param.instance_of?(
|
191
|
+
def validates_type_float(param)
|
192
|
+
return param if param.instance_of?(Float)
|
193
|
+
begin
|
194
|
+
return param.to_f
|
195
|
+
rescue StandardError
|
196
|
+
return :ERROR
|
197
|
+
end
|
190
198
|
end
|
191
199
|
|
192
|
-
def
|
193
|
-
param.instance_of?(
|
200
|
+
def validate_type_string(param)
|
201
|
+
return param if param.instance_of?(String)
|
202
|
+
begin
|
203
|
+
return param.to_s
|
204
|
+
rescue StandardError
|
205
|
+
return :ERROR
|
206
|
+
end
|
194
207
|
end
|
195
208
|
|
196
|
-
def
|
197
|
-
param.instance_of?(
|
209
|
+
def validates_type_date(param)
|
210
|
+
return param if param.instance_of?(Date)
|
211
|
+
begin
|
212
|
+
return Date.parse(param)
|
213
|
+
rescue StandardError
|
214
|
+
return :ERROR
|
215
|
+
end
|
198
216
|
end
|
199
217
|
|
200
|
-
def
|
201
|
-
param.instance_of?(
|
218
|
+
def validates_type_datetime(param)
|
219
|
+
return param if param.instance_of?(DateTime)
|
220
|
+
begin
|
221
|
+
return DateTime.parse(param)
|
222
|
+
rescue StandardError
|
223
|
+
return :ERROR
|
224
|
+
end
|
202
225
|
end
|
203
226
|
|
204
|
-
def
|
205
|
-
param.instance_of?(
|
227
|
+
def validates_type_hash(param)
|
228
|
+
return param if param.instance_of?(Hash)
|
229
|
+
:ERROR
|
230
|
+
end
|
231
|
+
|
232
|
+
def validates_type_array(param)
|
233
|
+
return param if param.instance_of?(Array)
|
234
|
+
:ERROR
|
206
235
|
end
|
207
236
|
|
208
237
|
end
|
data/lib/evnt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evnt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '3.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ideonetwork
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|