mv-mysql 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5ca9da93b16a59710ffc1d4c2bf5de9c8aac25f
4
- data.tar.gz: 88d232eb43849333adc5ce44024ff19098346363
3
+ metadata.gz: 8afb7fce57625da1922d14fd9176e0ca7f3d611d
4
+ data.tar.gz: 37417cb342588a253ca31141896ed8d782832670
5
5
  SHA512:
6
- metadata.gz: cfd2ec34508e35d53227dd4ad8cf24e13448056bb8c2535d5e9a8c0f842d51dd419ec4b7475d2a5783031e27d587e3a3d673be4fbb25b00fc41c0a0f27cf9842
7
- data.tar.gz: f8417bfcc539c632683c7bc4020f66bbaa0deeb8f177d78ded1809a7c952abe91608eeea67ad73c79e9a4c766ecd4ffedade134400d5b75096140d8c07b394e7
6
+ metadata.gz: 5ea89ba6401bbc0b8e29731304a189d54cc8c0733c42b2bdf518e33840fba71027d0042ed8078dd6cfd694623bed3d335d007206742429d696a24d5d735c8ffd
7
+ data.tar.gz: 8645bac19886ae85dee7526bb3e7eba8ff647a3fb674dcb17e5e88c04de0a5e4d139256e06bf5542e40d1b041f6390af805c6e765cc1ff4d152c9d227c29a893
data/README.md CHANGED
@@ -1,11 +1,10 @@
1
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/vprokopchuk256/mv-mysql/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
2
1
  [![Build Status](https://travis-ci.org/vprokopchuk256/mv-mysql.svg?branch=master)](https://travis-ci.org/vprokopchuk256/mv-mysql)
3
2
  [![Coverage Status](https://coveralls.io/repos/vprokopchuk256/mv-mysql/badge.png?branch=master)](https://coveralls.io/r/vprokopchuk256/mv-mysql?branch=master)
4
3
  [![Gem Version](https://badge.fury.io/rb/mv-mysql.svg)](http://badge.fury.io/rb/mv-mysql)
5
4
 
6
5
  # Introduction
7
6
 
8
- mv-mysql is the MySQL driver for Migration Validators project (details here: https://github.com/vprokopchuk256/mv-core)
7
+ mv-mysql is the MySQL driver for Migration Validators project (details here: https://github.com/vprokopchuk256/mv-core). Allows RoR developer to define database constraints in a familiar ActiveRecord validations manner
9
8
 
10
9
  # Validators
11
10
 
@@ -46,6 +45,14 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
46
45
  end
47
46
  ```
48
47
 
48
+ simplifications (version >= 2.1 is required):
49
+
50
+ ```ruby
51
+ create_table :table_name do |t|
52
+ t.string :column_name, uniqueness: true
53
+ end
54
+ ```
55
+
49
56
  Options:
50
57
 
51
58
  * `:message` - text of the error message that will be shown if constraint violated. Ignored unless `:as == :trigger`
@@ -83,6 +90,32 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
83
90
  length: { maximum: 3,
84
91
  too_long: 'Value is longer than 3 symbols' }
85
92
  ```
93
+
94
+ all above are available in a create and change table blocks:
95
+
96
+ ```ruby
97
+ create_table :table_name do |t|
98
+ t.string :column_name, validates: { length: { is: 3, allow_nil: true} }
99
+ end
100
+ ```
101
+
102
+ ```ruby
103
+ change :table_name do |t|
104
+ t.change :column_name, :string, validates: { length: { is: 3 } }
105
+ end
106
+ ```
107
+
108
+ simplifications (version >= 2.1 is required):
109
+
110
+ ```ruby
111
+ create_table :table_name do |t|
112
+ t.string :string_3, length: 3
113
+ t.string :string_from_1_to_3, length: 1..3,
114
+ t.string :string_1_or_3, length: [1, 3]
115
+ t.string :string_4, validates: { length: 4 }
116
+ t.string :string_4_in_trigger: length: { is: 4, as: :trigger }
117
+ end
118
+ ```
86
119
 
87
120
  Options:
88
121
 
@@ -105,10 +138,12 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
105
138
 
106
139
  Examples:
107
140
 
141
+ Examples:
142
+
108
143
  valid values array:
109
144
 
110
145
  ```ruby
111
- validates :table_name, :column_name, inclusion: { in: [1, 2, 3]}
146
+ validates :table_name, :column_name, inclusion: { in: [1, 2, 3] }
112
147
  ```
113
148
 
114
149
  with failure message specified:
@@ -119,6 +154,31 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
119
154
  message: "Column 'column_name' should be equal to 1 or 2 or 3" }
120
155
  ```
121
156
 
157
+ all above are available in a create and change table blocks:
158
+
159
+ ```ruby
160
+ create_table :table_name do |t|
161
+ t.integer :column_name, validates: { inclusion: { in: 1..3 } }
162
+ end
163
+ ```
164
+
165
+ ```ruby
166
+ change :table_name do |t|
167
+ t.change :column_name, :integer, validates: { inclusion: { in: 1..3 } }
168
+ end
169
+ ```
170
+
171
+ simplifications (version >= 2.1 is required):
172
+
173
+ ```ruby
174
+ create_table :table_name do |t|
175
+ t.string :str_or_str_1, inclusion: ['str', 'str1']
176
+ t.string :from_str_to_str_1, inclusion: 'str'..'str1'
177
+ t.string :str_or_str_1_in_trigger, inclusion: { in: ['str', 'str1'],
178
+ as: :trigger}
179
+ end
180
+ ```
181
+
122
182
  Options:
123
183
 
124
184
  * `:in range` - or array that column value should be contained in.
@@ -141,22 +201,38 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
141
201
  validates :table_name, :column_name, exclusion: { in: [1, 2, 3] }
142
202
  ```
143
203
 
144
- exclude values with specified failure message:
204
+ the same with failure message:
145
205
 
146
206
  ```ruby
147
207
  validates :table_name, :column_name,
148
- exclusion: {
149
- in: [1, 2, 3],
150
- message: "Column 'column_name' should not be equal to 1 or 2 or 3"
151
- }
208
+ exclusion: {
209
+ in: [1, 2, 3],
210
+ message: "Column 'column_name' should not be equal to 1 or 2 or 3" }
211
+ ```
212
+
213
+ all above are available in a create and change table blocks:
214
+
215
+ ```ruby
216
+ create_table :table_name do |t|
217
+ t.integer :column_name, validates: { exclusion: { in: 1..3 } }
218
+ end
152
219
  ```
153
220
 
154
- performs verification on update only:
221
+ ```ruby
222
+ change :table_name do |t|
223
+ t.change :column_name, :integer, validates: { exclusion: { in: 1..3 } }
224
+ end
225
+ ```
226
+
227
+ simplifications (version >= 2.1 is required):
155
228
 
156
229
  ```ruby
157
- validates :table_name, :column_name,
158
- exclusion: { in: [1, 2, 3],
159
- on: :update }
230
+ create_table :table_name do |t|
231
+ t.string :neither_str_nor_str_1, exclusion: ['str', 'str1']
232
+ t.string :from_str_to_str_1, exclusion: 'str'..'str1'
233
+ t.string :str_or_str_1_in_trigger, exclusion: { in: ['str', 'str1'],
234
+ as: :trigger}
235
+ end
160
236
  ```
161
237
 
162
238
  Options:
@@ -172,9 +248,7 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
172
248
 
173
249
  ### presence
174
250
 
175
- Examples:
176
-
177
- simple presence validator:
251
+ Examples:
178
252
 
179
253
  ```ruby
180
254
  validates :table_name, :column_name, presence: true
@@ -184,22 +258,44 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
184
258
 
185
259
  ```ruby
186
260
  validates :table_name, :column_name,
187
- :presence: { message: 'value should not be empty' }
261
+ presence: { message: 'value should not be empty' }
188
262
  ```
189
263
 
190
- performs verification only when new record is inserted:
264
+ check when record is inserted only:
191
265
 
192
266
  ```ruby
193
267
  validates :table_name, :column_name,
194
268
  presence: { message: 'value should not be empty',
269
+ as: :trigger,
195
270
  on: :create }
196
271
  ```
197
272
 
198
- ### absence
273
+ all above are available in a create and change table blocks:
199
274
 
200
- Examples:
275
+ ```ruby
276
+ create_table :table_name do |t|
277
+ t.string :column_name, validates: { presence: true }
278
+ end
279
+ ```
280
+
281
+ ```ruby
282
+ change :table_name do |t|
283
+ t.change :column_name, :string, validates: { presence: true }
284
+ end
285
+ ```
286
+
287
+ simplifications (version >= 2.1 is required):
288
+
289
+ ```ruby
290
+ create_table :table_name do |t|
291
+ t.string :presence_in_check, presence: true
292
+ t.string :presence_in_trigger, presence: { as: :trigger, on: :create }
293
+ end
294
+ ```
295
+
296
+ ### absence
201
297
 
202
- simple absence validator:
298
+ Examples:
203
299
 
204
300
  ```ruby
205
301
  validates :table_name, :column_name, absence: true
@@ -209,17 +305,98 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
209
305
 
210
306
  ```ruby
211
307
  validates :table_name, :column_name,
212
- :absence: { message: 'value should not empty' }
308
+ absence: { message: 'value should be empty' }
213
309
  ```
214
310
 
215
- performs verification only when new record is inserted:
311
+ check when record is inserted only:
216
312
 
217
313
  ```ruby
218
314
  validates :table_name, :column_name,
219
- absence: { message: 'value should not empty',
220
- on: :create }
315
+ absence: { message: 'value should be empty',
316
+ as: :trigger,
317
+ on: :create }
221
318
  ```
222
319
 
320
+ all above are available in a create and change table blocks:
321
+
322
+ ```ruby
323
+ create_table :table_name do |t|
324
+ t.string :column_name, validates: { absence: true }
325
+ end
326
+ ```
327
+
328
+ ```ruby
329
+ change :table_name do |t|
330
+ t.change :column_name, :string, validates: { absence: true }
331
+ end
332
+ ```
333
+
334
+ simplifications (version >= 2.1 is required):
335
+
336
+ ```ruby
337
+ create_table :table_name do |t|
338
+ t.string :absence_in_check, absence: true
339
+ t.string :absence_in_trigger, absence: { as: :trigger, on: :create }
340
+ end
341
+ ```
342
+
343
+ ### custom (version >= 2.1 is required)
344
+
345
+ Examples:
346
+
347
+ allows only values that equals 'word' when trimmed:
348
+
349
+ ```ruby
350
+ validates :table_name, :column_name,
351
+ custom: { statement: "TRIM({column_name}) = 'word'" }
352
+ ```
353
+
354
+ with failure message:
355
+
356
+ ```ruby
357
+ validates :table_name, :column_name,
358
+ custom: { statement: "TRIM({column_name}) = 'word'",
359
+ message: 'Column_name value should contain start word' }
360
+ ```
361
+
362
+ implemented as trigger on insert event:
363
+
364
+ ```ruby
365
+ validates :table_name, :column_name,
366
+ custom: { statement: "TRIM({column_name}) = 'word'",
367
+ message: 'Column_name value should contain start word',
368
+ as: :trigger,
369
+ on: :create }
370
+ ```
371
+
372
+ all above are available in a create and change table blocks:
373
+
374
+ ```ruby
375
+ create_table :table_name do |t|
376
+ t.string :column_name,
377
+ validates: { custom: { statement: "TRIM({column_name}) = 'word'"} }
378
+ end
379
+ ```
380
+
381
+ ```ruby
382
+ change :table_name do |t|
383
+ t.change :column_name, :string,
384
+ validates: { custom: { statement: "TRIM({column_name}) = 'word'"} }
385
+ end
386
+ ```
387
+
388
+ simplifications (version >= 2.1 is required):
389
+
390
+ ```ruby
391
+ create_table :table_name do |t|
392
+ t.string :contains_word, custom: "TRIM({contains_word}) = 'word'"
393
+ t.string :contains_word_synonym,
394
+ validates: "TRIM({contains_word_synonym}) = 'word'"
395
+ t.string :contains_word_in_trigger,
396
+ custom: { statement: "TRIM({contains_word_in_trigger}) = 'word'", as: :trigger }
397
+ end
398
+ ```
399
+
223
400
  Options:
224
401
 
225
402
  * `:message` - message that should be shown if validation failed
@@ -230,6 +407,74 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
230
407
  * `:allow_blank` - ignore validation for blank values. Default value: `false`
231
408
  * `:as` - defines the way how constraint will be implemented. Possible values: `[:trigger]`
232
409
 
410
+ ### custom (version >= 2.1 is required)
411
+
412
+ Examples:
413
+
414
+ allows only values that equals 'word' when trimmed:
415
+
416
+ ```ruby
417
+ validates :table_name, :column_name,
418
+ custom: { statement: "TRIM({column_name}) = 'word'" }
419
+ ```
420
+
421
+ with failure message:
422
+
423
+ ```ruby
424
+ validates :table_name, :column_name,
425
+ custom: { statement: "TRIM({column_name}) = 'word'",
426
+ message: 'Column_name value should contain start word' }
427
+ ```
428
+
429
+ implemented as trigger on insert event:
430
+
431
+ ```ruby
432
+ validates :table_name, :column_name,
433
+ custom: { statement: "TRIM({column_name}) = 'word'",
434
+ message: 'Column_name value should contain start word',
435
+ as: :trigger,
436
+ on: :create }
437
+ ```
438
+
439
+ all above are available in a create and change table blocks:
440
+
441
+ ```ruby
442
+ create_table :table_name do |t|
443
+ t.string :column_name,
444
+ validates: { custom: { statement: "TRIM({column_name}) = 'word'"} }
445
+ end
446
+ ```
447
+
448
+ ```ruby
449
+ change :table_name do |t|
450
+ t.change :column_name, :string,
451
+ validates: { custom: { statement: "TRIM({column_name}) = 'word'"} }
452
+ end
453
+ ```
454
+
455
+ simplifications (version >= 2.1 is required):
456
+
457
+ ```ruby
458
+ create_table :table_name do |t|
459
+ t.string :contains_word, custom: "TRIM({contains_word}) = 'word'"
460
+ t.string :contains_word_synonym,
461
+ validates: "TRIM({contains_word_synonym}) = 'word'"
462
+ t.string :contains_word_in_trigger,
463
+ custom: { statement: "TRIM({contains_word_in_trigger}) = 'word'", as: :trigger }
464
+ end
465
+ ```
466
+
467
+ Options:
468
+
469
+ * `statement` - db expression that column value should be matched to
470
+ * `message` - message that should be shown if validation failed
471
+ * `on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
472
+ * `create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
473
+ * `update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
474
+ * `allow_nil` - ignore validation for `nil` values. Default value: `false`
475
+ * `allow_blank` - ignore validation for blank values. Default value: `false`
476
+ * `as` - defines the way how constraint will be implemented. Possible values: `[:trigger]` Default value: `:trigger`
477
+
233
478
  ## Contributing to mv-mysql
234
479
 
235
480
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
@@ -9,6 +9,7 @@ require 'mv/mysql/validation/length'
9
9
  require 'mv/mysql/validation/presence'
10
10
  require 'mv/mysql/validation/absence'
11
11
  require 'mv/mysql/validation/uniqueness'
12
+ require 'mv/mysql/validation/custom'
12
13
 
13
14
  require 'mv/mysql/validation/builder/trigger/exclusion'
14
15
  require 'mv/mysql/validation/builder/trigger/inclusion'
@@ -16,6 +17,7 @@ require 'mv/mysql/validation/builder/trigger/length'
16
17
  require 'mv/mysql/validation/builder/trigger/presence'
17
18
  require 'mv/mysql/validation/builder/trigger/absence'
18
19
  require 'mv/mysql/validation/builder/trigger/uniqueness'
20
+ require 'mv/mysql/validation/builder/trigger/custom'
19
21
 
20
22
  ActiveSupport.on_load(:mv_core) do
21
23
 
@@ -31,27 +33,19 @@ ActiveSupport.on_load(:mv_core) do
31
33
  :length => Mv::Mysql::Validation::Length,
32
34
  :presence => Mv::Mysql::Validation::Presence,
33
35
  :absence => Mv::Mysql::Validation::Absence,
34
- :uniqueness => Mv::Mysql::Validation::Uniqueness
36
+ :uniqueness => Mv::Mysql::Validation::Uniqueness,
37
+ :custom => Mv::Mysql::Validation::Custom
35
38
  )
36
39
 
37
- #validation builders in trigger
40
+ # validation builders in trigger
38
41
  Mv::Mysql::Constraint::Builder::Trigger.validation_builders_factory.register_builders(
39
- Mv::Mysql::Validation::Exclusion => Mv::Mysql::Validation::Builder::Trigger::Exclusion ,
42
+ Mv::Mysql::Validation::Exclusion => Mv::Mysql::Validation::Builder::Trigger::Exclusion,
40
43
  Mv::Mysql::Validation::Inclusion => Mv::Mysql::Validation::Builder::Trigger::Inclusion,
41
44
  Mv::Mysql::Validation::Length => Mv::Mysql::Validation::Builder::Trigger::Length,
42
45
  Mv::Mysql::Validation::Presence => Mv::Mysql::Validation::Builder::Trigger::Presence,
43
46
  Mv::Mysql::Validation::Absence => Mv::Mysql::Validation::Builder::Trigger::Absence,
44
- Mv::Mysql::Validation::Uniqueness => Mv::Mysql::Validation::Builder::Trigger::Uniqueness
45
- )
46
-
47
- #validation builders in trigger
48
- Mv::Mysql::Constraint::Builder::Trigger.validation_builders_factory.register_builders(
49
- Mv::Core::Validation::Exclusion => Mv::Mysql::Validation::Builder::Trigger::Exclusion,
50
- Mv::Core::Validation::Inclusion => Mv::Mysql::Validation::Builder::Trigger::Inclusion,
51
- Mv::Core::Validation::Length => Mv::Mysql::Validation::Builder::Trigger::Length,
52
- Mv::Core::Validation::Presence => Mv::Mysql::Validation::Builder::Trigger::Presence,
53
- Mv::Core::Validation::Absence => Mv::Mysql::Validation::Builder::Trigger::Absence,
54
- Mv::Core::Validation::Uniqueness => Mv::Mysql::Validation::Builder::Trigger::Uniqueness
47
+ Mv::Mysql::Validation::Uniqueness => Mv::Mysql::Validation::Builder::Trigger::Uniqueness,
48
+ Mv::Mysql::Validation::Custom => Mv::Mysql::Validation::Builder::Trigger::Custom
55
49
  )
56
50
  end
57
51
 
@@ -0,0 +1,15 @@
1
+ require 'mv/mysql/validation/builder/trigger/trigger_column'
2
+
3
+ module Mv
4
+ module Mysql
5
+ module Validation
6
+ module Builder
7
+ module Trigger
8
+ class Custom < Mv::Core::Validation::Builder::Custom
9
+ include TriggerColumn
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require 'mv/mysql/validation/mysql_error_message_restrictions'
2
+
3
+ module Mv
4
+ module Mysql
5
+ module Validation
6
+ class Custom < Mv::Core::Validation::Custom
7
+ include MysqlErrorMessageRestrictions
8
+ end
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mv-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valeriy Prokopchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-19 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: '2.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: jeweler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -138,6 +138,7 @@ files:
138
138
  - lib/mv/mysql/railtie.rb
139
139
  - lib/mv/mysql/validation/absence.rb
140
140
  - lib/mv/mysql/validation/builder/trigger/absence.rb
141
+ - lib/mv/mysql/validation/builder/trigger/custom.rb
141
142
  - lib/mv/mysql/validation/builder/trigger/exclusion.rb
142
143
  - lib/mv/mysql/validation/builder/trigger/inclusion.rb
143
144
  - lib/mv/mysql/validation/builder/trigger/length.rb
@@ -145,6 +146,7 @@ files:
145
146
  - lib/mv/mysql/validation/builder/trigger/presence.rb
146
147
  - lib/mv/mysql/validation/builder/trigger/trigger_column.rb
147
148
  - lib/mv/mysql/validation/builder/trigger/uniqueness.rb
149
+ - lib/mv/mysql/validation/custom.rb
148
150
  - lib/mv/mysql/validation/exclusion.rb
149
151
  - lib/mv/mysql/validation/inclusion.rb
150
152
  - lib/mv/mysql/validation/length.rb