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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0db0ec5e816f260aec22fafce15157c977a7049e
4
- data.tar.gz: 11724ef2038b70663bd77f75082f45ebca3fbde6
3
+ metadata.gz: ef2fa95d09eb421d9912263783747d85451a4d5e
4
+ data.tar.gz: af36eef1ef9d3c940e68c2eb6ee0b35b3212964c
5
5
  SHA512:
6
- metadata.gz: 3d04d6350a5c1ae9a25884ec74b0f101a47ef94cb30c2c786a770d2ce21b20598267fd180899069b41c04f2379bf80d18e5e7fa801c6dec6410df8bf6008e763
7
- data.tar.gz: 3d327824989463e5aec34a10833cf6683dcdbd89c098cfd97434b0bb38ea0aa95d3b4b51ee4f988616b281532a5b59a66bdc982b6dd83d971513de8670b3c2bd
6
+ metadata.gz: d40c2f8c4e51b0d505911f3059da2b2f4d4ade398131f20c38797da2e1f4ad370858b9dcf3843521ae91529ed0331cdf4a47fd6a6b2137a3751a5cd486bb5d61
7
+ data.tar.gz: ada5ce42640430d0f38c4773461be4edb5a012c64b20253e6a12a76cd3b0d5d47835100078e2645cfb2fd98d37c620e172cf44a53da1a3abdbddbffdea0d1728
@@ -118,7 +118,7 @@ module Evnt
118
118
  }
119
119
 
120
120
  # set other data
121
- @params = params.freeze
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
- unless result
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:
@@ -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
- return false unless validate_option(param, key, value)
32
+ result = validate_option(result, key, value)
33
+ break if result == :ERROR
32
34
  end
33
35
 
34
- true
36
+ result
35
37
  rescue StandardError => e
36
38
  puts e
37
- false
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
- false
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 true if param.nil?
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
- false
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
- false
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
- rescue StandardError => e
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
- false
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 validate_type_boolean(param)
177
- param.instance_of?(TrueClass) || param.instance_of?(FalseClass)
170
+ def validate_type_symbol(param)
171
+ return param if param.instance_of?(Symbol)
172
+ :ERROR
178
173
  end
179
174
 
180
- def validate_type_string(param)
181
- param.instance_of?(String)
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 validate_type_symbol(param)
189
- param.instance_of?(Symbol)
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 validates_type_float(param)
193
- param.instance_of?(Float)
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 validates_type_hash(param)
197
- param.instance_of?(Hash)
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 validates_type_array(param)
201
- param.instance_of?(Array)
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 validates_type_date(param)
205
- param.instance_of?(Date)
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
@@ -5,6 +5,6 @@ module Evnt
5
5
  ##
6
6
  # Constant containing the current gem version.
7
7
  ##
8
- VERSION = '2.1.5'
8
+ VERSION = '3.0'
9
9
 
10
10
  end
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: 2.1.5
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-14 00:00:00.000000000 Z
11
+ date: 2017-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler