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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b47e9514c1003fc6c670c61af7b5d19974e479e27282ce09328abb2738fa7508
4
- data.tar.gz: 9e47da764eb7806cb411c120332280b4bd8bf5a6d0ff4bd8f16f0dabfe9e5be2
3
+ metadata.gz: bc9c2d44adbb7ee8e0082f744346a0833023632850642e7e94d0a358f764c2db
4
+ data.tar.gz: 65a91b5fe0e78d65230d77cf2767e698cd618dc0396bb0b38ab037a45b8fa3a2
5
5
  SHA512:
6
- metadata.gz: f318bbaace2c47ede9c46efbdf87c5cbe85a67c021ddec28db6a879c458770c2e2cde0cb47c66bfae2351408aa49aad4040e860bd31374bfe5384b339120f870
7
- data.tar.gz: a3275d02c0ed51b194c04452f654bca1202b7f47dde5f2bd707b35d096c229c6246e283f492bac3b5896ca6c9ff4173b6f361cd338f5765c23cdd54f9caa3291
6
+ metadata.gz: af6ccac3e011ed907d6754bcc578266c4b32db804088acf49ef9e52b6a11a2b7ae0407f7602dd81f40814039eaed161456377dab03b195f5f1133caea6dd0abb
7
+ data.tar.gz: 3fda181648b4c314dc7f22ded9fd9f2aef9ab77c110bb743d19e4442463f06f2e1416ef71e19652fe65d0aee5716f6f68fc9acaef37e69d7b120ffac99a0ba15
@@ -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
- validator = Evnt::Validator.new(params[val[:param]], val[:options])
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)
@@ -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)
@@ -3,6 +3,6 @@
3
3
  # Evnt.
4
4
  module Evnt
5
5
 
6
- VERSION = '3.1.2'
6
+ VERSION = '3.1.3'
7
7
 
8
8
  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: 3.1.2
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-02-27 00:00:00.000000000 Z
11
+ date: 2018-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler