evnt 3.1.2 → 3.1.3
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 +20 -4
- data/lib/evnt/event.rb +7 -2
- data/lib/evnt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc9c2d44adbb7ee8e0082f744346a0833023632850642e7e94d0a358f764c2db
|
4
|
+
data.tar.gz: 65a91b5fe0e78d65230d77cf2767e698cd618dc0396bb0b38ab037a45b8fa3a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af6ccac3e011ed907d6754bcc578266c4b32db804088acf49ef9e52b6a11a2b7ae0407f7602dd81f40814039eaed161456377dab03b195f5f1133caea6dd0abb
|
7
|
+
data.tar.gz: 3fda181648b4c314dc7f22ded9fd9f2aef9ab77c110bb743d19e4442463f06f2e1416ef71e19652fe65d0aee5716f6f68fc9acaef37e69d7b120ffac99a0ba15
|
data/lib/evnt/command.rb
CHANGED
@@ -25,6 +25,8 @@ module Evnt
|
|
25
25
|
# ==== Options
|
26
26
|
#
|
27
27
|
# * +exceptions+ - Boolean value used to activate the throw of excetions.
|
28
|
+
# * +nullify_empty_params+ - Transform empty params to nil values so the validator
|
29
|
+
# should consider them as nil values.
|
28
30
|
##
|
29
31
|
def initialize(params = {})
|
30
32
|
_init_command_data(params)
|
@@ -113,9 +115,10 @@ module Evnt
|
|
113
115
|
}
|
114
116
|
|
115
117
|
# set options
|
116
|
-
options = params[:_options] || {}
|
118
|
+
options = params[:_options] || @_default_options || {}
|
117
119
|
@options = {
|
118
|
-
exceptions: options[:exceptions] || false
|
120
|
+
exceptions: options[:exceptions] || false,
|
121
|
+
nullify_empty_params: options[:nullify_empty_params] || false
|
119
122
|
}
|
120
123
|
|
121
124
|
# set other data
|
@@ -136,7 +139,8 @@ module Evnt
|
|
136
139
|
return if self.class._validations.nil? || self.class._validations.empty?
|
137
140
|
|
138
141
|
self.class._validations.each do |val|
|
139
|
-
|
142
|
+
value_to_validate = _value_to_validate(val)
|
143
|
+
validator = Evnt::Validator.new(value_to_validate, val[:options])
|
140
144
|
|
141
145
|
if validator.passed?
|
142
146
|
@params[val[:param]] = validator.value
|
@@ -149,13 +153,25 @@ module Evnt
|
|
149
153
|
@params
|
150
154
|
end
|
151
155
|
|
156
|
+
def _value_to_validate(val)
|
157
|
+
return nil if @options[:nullify_empty_params] && params[val[:param]].empty?
|
158
|
+
params[val[:param]]
|
159
|
+
rescue StandardError
|
160
|
+
params[val[:param]]
|
161
|
+
end
|
162
|
+
|
152
163
|
# Class functions:
|
153
164
|
############################################################################
|
154
165
|
|
155
166
|
# This class contain the list of settings for the command.
|
156
167
|
class << self
|
157
168
|
|
158
|
-
attr_accessor :_validations
|
169
|
+
attr_accessor :_default_options, :_validations
|
170
|
+
|
171
|
+
# This function sets the default options that should be used by the command.
|
172
|
+
def default_options(options)
|
173
|
+
instance_variable_set(:@_default_options, options)
|
174
|
+
end
|
159
175
|
|
160
176
|
# This function sets the single validation request for a command parameter.
|
161
177
|
def validates(param, options)
|
data/lib/evnt/event.rb
CHANGED
@@ -78,7 +78,7 @@ module Evnt
|
|
78
78
|
}
|
79
79
|
|
80
80
|
# set options
|
81
|
-
options = params[:_options] || {}
|
81
|
+
options = params[:_options] || @_default_options || {}
|
82
82
|
@options = {
|
83
83
|
silent: options[:silent] || false
|
84
84
|
}
|
@@ -139,7 +139,12 @@ module Evnt
|
|
139
139
|
# This class contain the list of settings for the event.
|
140
140
|
class << self
|
141
141
|
|
142
|
-
attr_accessor :_name, :_attributes, :_handlers
|
142
|
+
attr_accessor :_default_options, :_name, :_attributes, :_handlers
|
143
|
+
|
144
|
+
# This function sets the default options that should be used by the event.
|
145
|
+
def default_options(options)
|
146
|
+
instance_variable_set(:@_default_options, options)
|
147
|
+
end
|
143
148
|
|
144
149
|
# This function sets the name for the event.
|
145
150
|
def name_is(event_name)
|
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: 3.1.
|
4
|
+
version: 3.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ideonetwork
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|