mv-postgresql 2.1.0 → 2.2.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: 5312214a363c7e4dd85d54c07bc72f29791d7ba7
4
- data.tar.gz: 58a0227278138a421c75bdee96ee1bf72b616b2c
3
+ metadata.gz: 94eefeb9c7c044f630e3cb2662f623b2c40698e9
4
+ data.tar.gz: 2f43fd4ed316b6e55f296fbd34245e7a03fe4ac9
5
5
  SHA512:
6
- metadata.gz: 560d9087028db2e17a187ac876ac9fee9ec467f4cb4df27ec63a3a24c614e690c0907cda91a7445f49e17b04c14ae4173a1d1cc934c7decc7c5886bd9db09ddd
7
- data.tar.gz: 8ac04ec6d42cf0492d3c28efbb5301b3fed8e86e02f7fee0131ce60dc0c8450898040b155bb658418fb77cc058edffbb360d462ad06a5f04037f342d3341e3c8
6
+ metadata.gz: 4e9a36dc51c29c4e46ddaf5e11e497d56a848324f6184ff9cd50a26f0ad2b830b557d599903f32704762e9c439f451910984839983f30799ee733e85106545df
7
+ data.tar.gz: 31a0708571c79086c918343565e03fb63e484585671996b8ba73799923bbe9104d701e744b092ab9aebec284277a801b046d40870ccf0153bc4aeb8dab73e2a8
data/README.md CHANGED
@@ -2,11 +2,24 @@
2
2
  [![Coverage Status](https://coveralls.io/repos/vprokopchuk256/mv-postgresql/badge.png?branch=master)](https://coveralls.io/r/vprokopchuk256/mv-postgresql?branch=master)
3
3
  [![Gem Version](https://badge.fury.io/rb/mv-postgresql.svg)](http://badge.fury.io/rb/mv-postgresql)
4
4
 
5
- # Introduction
5
+ # `Migration Validators` project. PostgreSQL driver.
6
6
 
7
- mv-postgresql is the PostgreSQL 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
7
+ Define validations directly in DB as PostgreSQL constraints and integrate them into your model transparently. See [mv-core](https://github.com/vprokopchuk256/mv-core) for details. There you will be able to review high level project information. Below you can see details of the migration validations that are supported by PostgreSQL driver.
8
8
 
9
- # Validators
9
+ #Table Of Contents
10
+ * [Validations](#validations)
11
+ * [uniqueness](#uniqueness)
12
+ * [length](#length)
13
+ * [inclusion](#inclusion)
14
+ * [exclusion](#exclusion)
15
+ * [presence](#presence)
16
+ * [absence](#absence)
17
+ * [format](#format)
18
+ * [custom](#custom)
19
+ * [Version History](#version history)
20
+ * [Contributing](#contributing)
21
+
22
+ # Validations
10
23
 
11
24
  ### uniqueness
12
25
 
@@ -15,41 +28,71 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
15
28
  validate uniqueness of the column `column_name`:
16
29
 
17
30
  ```ruby
18
- validates :table_name, :column_name, uniqueness: true
31
+ def up
32
+ validates :table_name, :column_name, uniqueness: true
33
+ end
34
+
35
+ def down
36
+ validates :table_name, :column_name, uniqueness: false
37
+ end
19
38
  ```
20
39
 
21
40
  define validation as trigger with specified failure message:
22
41
 
23
42
  ```ruby
24
- validates :table_name, :column_name,
25
- uniqueness: { message: 'Error message', as: :trigger }
43
+ def up
44
+ validates :table_name, :column_name,
45
+ uniqueness: { message: 'Error message', as: :trigger }
46
+ end
47
+
48
+ def down
49
+ validates :table_name, :column_name, uniqueness: false
50
+ end
26
51
  ```
27
52
 
28
53
  define validation as unique index:
29
54
 
30
55
  ```ruby
31
- validates :table_name, :column_name, uniqueness: { as: :index }
56
+ def up
57
+ validates :table_name, :column_name, uniqueness: { as: :index }
58
+ end
59
+
60
+ def down
61
+ validates :table_name, :column_name, uniqueness: false
62
+ end
32
63
  ```
33
64
 
34
65
  all above are available in a create and change table blocks:
35
66
 
36
67
  ```ruby
37
- create_table :table_name do |t|
38
- t.string :column_name, validates: { uniqueness: true }
68
+ def change
69
+ create_table :table_name do |t|
70
+ t.string :column_name, validates: { uniqueness: true }
71
+ end
39
72
  end
40
73
  ```
41
74
 
42
75
  ```ruby
43
- change :table_name do |t|
44
- t.change :column_name, :string, validates: { uniqueness: false }
76
+ def up
77
+ change :table_name do |t|
78
+ t.change :column_name, :string, validates: { uniqueness: false }
79
+ end
80
+ end
81
+
82
+ def down
83
+ change :table_name do |t|
84
+ t.change :column_name, :string, validates: { uniqueness: false }
85
+ end
45
86
  end
46
87
  ```
47
88
 
48
89
  simplifications (version >= 2.1 is required):
49
90
 
50
91
  ```ruby
51
- create_table :table_name do |t|
52
- t.string :column_name, uniqueness: true
92
+ def change
93
+ create_table :table_name do |t|
94
+ t.string :column_name, uniqueness: true
95
+ end
53
96
  end
54
97
  ```
55
98
 
@@ -69,58 +112,94 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
69
112
  Examples:
70
113
 
71
114
  ```ruby
72
- validates :table_name, :column_name,
73
- length: { in: 5..8, message: 'Wrong length message'}
115
+ def up
116
+ validates :table_name, :column_name,
117
+ length: { in: 5..8, message: 'Wrong length message'}
118
+ end
119
+
120
+ def down
121
+ validates :table_name, :column_name, length: false
122
+ end
74
123
  ```
75
124
 
76
125
  allow `NULL`:
77
126
 
78
127
  ```ruby
79
- validates :table_name, :column_name,
80
- length: { is: 3, allow_nil: true}
128
+ def up
129
+ validates :table_name, :column_name,
130
+ length: { is: 3, allow_nil: true}
131
+ end
132
+
133
+ def down
134
+ validates :table_name, :column_name, length: false
135
+ end
81
136
  ```
82
137
 
83
138
  allow blank values:
84
139
 
85
140
  ```ruby
86
- validates :table_name, :column_name,
87
- length: { maximum: 3,
88
- allow_blank: true,
89
- too_long: 'Value is longer than 3 symbols' }
141
+ def up
142
+ validates :table_name, :column_name,
143
+ length: { maximum: 3,
144
+ allow_blank: true,
145
+ too_long: 'Value is longer than 3 symbols' }
146
+ end
147
+
148
+ def down
149
+ validates :table_name, :column_name, length: false
150
+ end
90
151
  ```
91
152
 
92
153
  define constraint in trigger:
93
154
 
94
155
  ```ruby
95
- validates :table_name, :column_name,
96
- length: { maximum: 3,
97
- as: :trigger,
98
- too_long: 'Value is longer than 3 symbols' }
156
+ def up
157
+ validates :table_name, :column_name,
158
+ length: { maximum: 3,
159
+ as: :trigger,
160
+ too_long: 'Value is longer than 3 symbols' }
161
+ end
162
+
163
+ def down
164
+ validates :table_name, :column_name, length: false
165
+ end
99
166
  ```
100
167
 
101
168
  all above are available in a create and change table blocks:
102
169
 
103
170
  ```ruby
104
- create_table :table_name do |t|
105
- t.string :column_name, validates: { length: { is: 3, allow_nil: true} }
171
+ def change
172
+ create_table :table_name do |t|
173
+ t.string :column_name, validates: { length: { is: 3, allow_nil: true} }
174
+ end
106
175
  end
107
176
  ```
108
177
 
109
178
  ```ruby
110
- change :table_name do |t|
111
- t.change :column_name, :string, validates: { length: { is: 3 } }
179
+ def up
180
+ change :table_name do |t|
181
+ t.change :column_name, :string, validates: { length: { is: 3 } }
182
+ end
183
+ end
184
+
185
+ def down
186
+ change :table_name do |t|
187
+ t.change :column_name, :string, validates: { length: false }
188
+ end
112
189
  end
113
190
  ```
114
191
 
115
192
  simplifications (version >= 2.1 is required):
116
193
 
117
194
  ```ruby
118
- create_table :table_name do |t|
119
- t.string :string_3, length: 3
120
- t.string :string_from_1_to_3, length: 1..3,
121
- t.string :string_1_or_3, length: [1, 3]
122
- t.string :string_4, validates: { length: 4 }
123
- t.string :string_4_in_trigger: length: { is: 4, as: :trigger }
195
+ def change
196
+ create_table :table_name do |t|
197
+ t.string :string_3, length: 3
198
+ t.string :string_from_1_to_3, length: 1..3,
199
+ t.string :string_1_or_3, length: [1, 3]
200
+ t.string :string_4, validates: { length: 4 }
201
+ t.string :string_4_in_trigger: length: { is: 4, as: :trigger }
202
+ end
124
203
  end
125
204
  ```
126
205
 
@@ -148,55 +227,91 @@ allow `NULL`:
148
227
  valid values array:
149
228
 
150
229
  ```ruby
151
- validates :table_name, :column_name, inclusion: { in: [1, 2, 3] }
230
+ def up
231
+ validates :table_name, :column_name, inclusion: { in: [1, 2, 3] }
232
+ end
233
+
234
+ def down
235
+ validates :table_name, :column_name, inclusion: false
236
+ end
152
237
  ```
153
238
 
154
239
  with failure message specified:
155
240
 
156
241
  ```ruby
157
- validates :table_name, :column_name,
158
- inclusion: { in: [1, 2, 3],
159
- message: "Column 'column_name' should be equal to 1 or 2 or 3" }
242
+ def up
243
+ validates :table_name, :column_name,
244
+ inclusion: { in: [1, 2, 3],
245
+ message: "Column value should be equal to 1 or 2 or 3" }
246
+ end
247
+
248
+ def down
249
+ validates :table_name, :column_name, inclusion: false
250
+ end
160
251
  ```
161
252
 
162
253
  make it as check constraint:
163
254
 
164
255
  ```ruby
165
- validates :table_name, :column_name,
166
- inclusion: { in: [1, 2, 3], as: :check }
256
+ def up
257
+ validates :table_name, :column_name,
258
+ inclusion: { in: [1, 2, 3], as: :check }
259
+ end
260
+
261
+ def down
262
+ validates :table_name, :column_name, inclusion: false
263
+ end
167
264
  ```
168
265
 
169
266
  make it in trigger:
170
267
 
171
268
  ```ruby
172
- validates :table_name, :column_name,
173
- inclusion: { in: 1..3,
174
- on: :create,
175
- as: :trigger }
269
+ def up
270
+ validates :table_name, :column_name,
271
+ inclusion: { in: 1..3,
272
+ on: :create,
273
+ as: :trigger }
274
+ end
275
+
276
+ def down
277
+ validates :table_name, :column_name, inclusion: false
278
+ end
176
279
  ```
177
280
 
178
281
  all above are available in a create and change table blocks:
179
282
 
180
283
  ```ruby
181
- create_table :table_name do |t|
182
- t.integer :column_name, validates: { inclusion: { in: 1..3 } }
284
+ def change
285
+ create_table :table_name do |t|
286
+ t.integer :column_name, validates: { inclusion: { in: 1..3 } }
287
+ end
183
288
  end
184
289
  ```
185
290
 
186
291
  ```ruby
187
- change :table_name do |t|
188
- t.change :column_name, :integer, validates: { inclusion: { in: 1..3 } }
292
+ def up
293
+ change :table_name do |t|
294
+ t.change :column_name, :integer, validates: { inclusion: { in: 1..3 } }
295
+ end
296
+ end
297
+
298
+ def down
299
+ change :table_name do |t|
300
+ t.change :column_name, :integer, validates: { inclusion: false }
301
+ end
189
302
  end
190
303
  ```
191
304
 
192
305
  simplifications (version >= 2.1 is required):
193
306
 
194
307
  ```ruby
195
- create_table :table_name do |t|
196
- t.string :str_or_str_1, inclusion: ['str', 'str1']
197
- t.string :from_str_to_str_1, inclusion: 'str'..'str1'
198
- t.string :str_or_str_1_in_trigger, inclusion: { in: ['str', 'str1'],
199
- as: :trigger}
308
+ def change
309
+ create_table :table_name do |t|
310
+ t.string :str_or_str_1, inclusion: ['str', 'str1']
311
+ t.string :from_str_to_str_1, inclusion: 'str'..'str1'
312
+ t.string :str_or_str_1_in_trigger, inclusion: { in: ['str', 'str1'],
313
+ as: :trigger}
314
+ end
200
315
  end
201
316
  ```
202
317
 
@@ -221,64 +336,102 @@ allow `NULL`:
221
336
  within `create_table` statement:
222
337
 
223
338
  ```ruby
224
- create_tablel :tabld_name do |t|
225
- t.integer :column_name, validates: { exclusion: { in: [1, 2, 3] } }
339
+ def change
340
+ create_table :tabld_name do |t|
341
+ t.integer :column_name, validates: { exclusion: { in: [1, 2, 3] } }
342
+ end
226
343
  end
227
344
  ```
228
345
 
229
346
  or as standalone statements:
230
347
 
231
348
  ```ruby
232
- validates :table_name, :column_name, exclusion: { in: [1, 2, 3] }
349
+ def up
350
+ validates :table_name, :column_name, exclusion: { in: [1, 2, 3] }
351
+ end
352
+
353
+ def down
354
+ validates :table_name, :column_name, exclusion: false
355
+ end
233
356
  ```
234
357
 
235
358
  the same with failure message:
236
359
 
237
360
  ```ruby
238
- validates :table_name, :column_name,
239
- exclusion: {
240
- in: [1, 2, 3],
241
- message: "Column 'column_name' should not be equal to 1 or 2 or 3" }
361
+ def up
362
+ validates :table_name, :column_name,
363
+ exclusion: {
364
+ in: [1, 2, 3],
365
+ message: "Column 'column_name' should not be equal to 1 or 2 or 3" }
366
+ end
367
+
368
+ def down
369
+ validates :table_name, :column_name, exclusion: false
370
+ end
242
371
  ```
243
372
 
244
373
  as check constraint:
245
374
 
246
375
  ```ruby
376
+ def up
247
377
  validates :table_name, :column_name,
248
378
  exclusion: { in: [1, 2, 3], as: :check }
379
+ end
380
+
381
+ def down
382
+ validates :table_name, :column_name, exclusion: false
383
+ end
249
384
  ```
250
385
 
251
386
  as trigger:
252
387
 
253
388
  ```ruby
389
+ def up
254
390
  validates :table_name, :column_name,
255
391
  exclusion: { in: 1..3,
256
392
  on: :create,
257
393
  as: :trigger }
394
+ end
395
+
396
+ def down
397
+ validates :table_name, :column_name, exclusion: false
398
+ end
258
399
  ```
259
400
 
260
401
  all above are available in a create and change table blocks:
261
402
 
262
403
  ```ruby
263
- create_table :table_name do |t|
264
- t.integer :column_name, validates: { exclusion: { in: 1..3 } }
404
+ def change
405
+ create_table :table_name do |t|
406
+ t.integer :column_name, validates: { exclusion: { in: 1..3 } }
407
+ end
265
408
  end
266
409
  ```
267
410
 
268
411
  ```ruby
269
- change :table_name do |t|
270
- t.change :column_name, :integer, validates: { exclusion: { in: 1..3 } }
412
+ def up
413
+ change :table_name do |t|
414
+ t.change :column_name, :integer, validates: { exclusion: { in: 1..3 } }
415
+ end
416
+ end
417
+
418
+ def down
419
+ change :table_name do |t|
420
+ t.change :column_name, :integer, validates: { exclusion: false }
421
+ end
271
422
  end
272
423
  ```
273
424
 
274
425
  simplifications (version >= 2.1 is required):
275
426
 
276
427
  ```ruby
277
- create_table :table_name do |t|
278
- t.string :neither_str_nor_str_1, exclusion: ['str', 'str1']
279
- t.string :from_str_to_str_1, exclusion: 'str'..'str1'
280
- t.string :str_or_str_1_in_trigger, exclusion: { in: ['str', 'str1'],
281
- as: :trigger}
428
+ def change
429
+ create_table :table_name do |t|
430
+ t.string :neither_str_nor_str_1, exclusion: ['str', 'str1']
431
+ t.string :from_str_to_str_1, exclusion: 'str'..'str1'
432
+ t.string :str_or_str_1_in_trigger, exclusion: { in: ['str', 'str1'],
433
+ as: :trigger}
434
+ end
282
435
  end
283
436
  ```
284
437
 
@@ -298,44 +451,78 @@ allow `NULL`:
298
451
  Examples:
299
452
 
300
453
  ```ruby
301
- validates :table_name, :column_name, presence: true
454
+ def up
455
+ validates :table_name, :column_name, presence: true
456
+ end
457
+
458
+ def down
459
+ validates :table_name, :column_name, presence: false
460
+ end
302
461
  ```
303
462
 
304
463
  with failure message:
305
464
 
306
465
  ```ruby
307
- validates :table_name, :column_name,
308
- presence: { message: 'value should not be empty' }
466
+ def up
467
+ validates :table_name, :column_name,
468
+ presence: { message: 'value should not be empty' }
469
+ end
470
+
471
+ def down
472
+ validates :table_name, :column_name, presence: false
473
+ end
309
474
  ```
310
475
 
311
476
  implemented as trigger:
312
477
 
313
478
  ```ruby
314
- validates :table_name, :column_name,
315
- presence: { message: 'value should not be empty',
316
- as: :trigger }
479
+ def up
480
+ validates :table_name, :column_name,
481
+ presence: { message: 'value should not be empty',
482
+ as: :trigger }
483
+ end
484
+
485
+ def down
486
+ validates :table_name, :column_name, presence: false
487
+ end
317
488
  ```
318
489
 
319
490
  check when record is inserted only:
320
491
 
321
492
  ```ruby
322
- validates :table_name, :column_name,
323
- presence: { message: 'value should not be empty',
324
- as: :trigger,
325
- on: :create }
493
+ def up
494
+ validates :table_name, :column_name,
495
+ presence: { message: 'value should not be empty',
496
+ as: :trigger,
497
+ on: :create }
498
+ end
499
+
500
+ def down
501
+ validates :table_name, :column_name, presence: false
502
+ end
326
503
  ```
327
504
 
328
505
  all above are available in a create and change table blocks:
329
506
 
330
507
  ```ruby
331
- create_table :table_name do |t|
332
- t.string :column_name, validates: { presence: true }
508
+ def change
509
+ create_table :table_name do |t|
510
+ t.string :column_name, validates: { presence: true }
511
+ end
333
512
  end
334
513
  ```
335
514
 
336
515
  ```ruby
337
- change :table_name do |t|
338
- t.change :column_name, :string, validates: { presence: true }
516
+ def up
517
+ change :table_name do |t|
518
+ t.change :column_name, :string, validates: { presence: true }
519
+ end
520
+ end
521
+
522
+ def down
523
+ change :table_name do |t|
524
+ t.change :column_name, :string, validates: { presence: false }
525
+ end
339
526
  end
340
527
  ```
341
528
 
@@ -363,53 +550,89 @@ allow `NULL`:
363
550
  Examples:
364
551
 
365
552
  ```ruby
366
- validates :table_name, :column_name, absence: true
553
+ def up
554
+ validates :table_name, :column_name, absence: true
555
+ end
556
+
557
+ def down
558
+ validates :table_name, :column_name, absence: false
559
+ end
367
560
  ```
368
561
 
369
562
  with failure message:
370
563
 
371
564
  ```ruby
372
- validates :table_name, :column_name,
373
- absence: { message: 'value should be empty' }
565
+ def up
566
+ validates :table_name, :column_name,
567
+ absence: { message: 'value should be empty' }
568
+ end
569
+
570
+ def down
571
+ validates :table_name, :column_name, absence: false
572
+ end
374
573
  ```
375
574
 
376
575
  implemented as trigger:
377
576
 
378
577
  ```ruby
379
- validates :table_name, :column_name,
380
- absence: { message: 'value should be empty',
381
- as: :trigger }
578
+ def up
579
+ validates :table_name, :column_name,
580
+ absence: { message: 'value should be empty',
581
+ as: :trigger }
582
+ end
583
+
584
+ def down
585
+ validates :table_name, :column_name, absence: false
586
+ end
382
587
  ```
383
588
 
384
589
  check when record is inserted only:
385
590
 
386
591
  ```ruby
387
- validates :table_name, :column_name,
388
- absence: { message: 'value should be empty',
389
- as: :trigger,
390
- on: :create }
592
+ def up
593
+ validates :table_name, :column_name,
594
+ absence: { message: 'value should be empty',
595
+ as: :trigger,
596
+ on: :create }
597
+ end
598
+
599
+ def down
600
+ validates :table_name, :column_name, absence: false
601
+ end
391
602
  ```
392
603
 
393
604
  all above are available in a create and change table blocks:
394
605
 
395
606
  ```ruby
396
- create_table :table_name do |t|
397
- t.string :column_name, validates: { absence: true }
607
+ def change
608
+ create_table :table_name do |t|
609
+ t.string :column_name, validates: { absence: true }
610
+ end
398
611
  end
399
612
  ```
400
613
 
401
614
  ```ruby
402
- change :table_name do |t|
403
- t.change :column_name, :string, validates: { absence: true }
615
+ def up
616
+ change :table_name do |t|
617
+ t.change :column_name, :string, validates: { absence: true }
618
+ end
619
+ end
620
+
621
+ def down
622
+ change :table_name do |t|
623
+ t.change :column_name, :string, validates: { absence: false }
624
+ end
404
625
  end
405
626
  ```
406
627
 
407
628
  simplifications (version >= 2.1 is required):
408
629
 
409
630
  ```ruby
410
- create_table :table_name do |t|
411
- t.string :absence_in_check, absence: true
412
- t.string :absence_in_trigger, absence: { as: :trigger, on: :create }
631
+ def change
632
+ create_table :table_name do |t|
633
+ t.string :absence_in_check, absence: true
634
+ t.string :absence_in_trigger, absence: { as: :trigger, on: :create }
635
+ end
413
636
  end
414
637
  ```
415
638
 
@@ -430,46 +653,77 @@ allow `NULL`:
430
653
  allows only values that contains 'word' inside:
431
654
 
432
655
  ```ruby
433
- validates :table_name, :column_name, format: { with: /word/ }
656
+ def up
657
+ validates :table_name, :column_name, format: { with: /word/ }
658
+ end
659
+
660
+ def down
661
+ validates :table_name, :column_name, format: false
662
+ end
434
663
  ```
435
664
 
436
665
  with failure message:
437
666
 
438
667
  ```ruby
668
+ def up
439
669
  validates :table_name, :column_name,
440
670
  format: { with: /word/,
441
671
  message: 'Column_name value should contain start word' }
672
+ end
673
+
674
+ def down
675
+ validates :table_name, :column_name, format: false
676
+ end
442
677
  ```
443
678
 
444
679
  implemented as trigger:
445
680
 
446
681
  ```ruby
447
- validates :table_name, :column_name,
448
- format: { with: /word/,
449
- message: 'Column_name value should contain start word',
450
- as: :trigger }
682
+ def up
683
+ validates :table_name, :column_name,
684
+ format: { with: /word/,
685
+ message: 'Column_name value should contain start word',
686
+ as: :trigger }
687
+ end
688
+
689
+ def down
690
+ validates :table_name, :column_name, format: false
691
+ end
451
692
  ```
452
693
 
453
694
  all above are available in a create and change table blocks:
454
695
 
455
696
  ```ruby
456
- create_table :table_name do |t|
457
- t.string :column_name, validates { format: { with: /word/ } }
697
+ def change
698
+ create_table :table_name do |t|
699
+ t.string :column_name, validates { format: { with: /word/ } }
700
+ end
458
701
  end
459
702
  ```
460
703
 
461
704
  ```ruby
462
- change :table_name do |t|
463
- t.change :column_name, :string, validates: { format: { with: /word/ } }
705
+ def up
706
+ change :table_name do |t|
707
+ t.change :column_name, :string, validates: { format: { with: /word/ } }
708
+ end
709
+ end
710
+
711
+ def down
712
+ change :table_name do |t|
713
+ t.change :column_name, :string, validates: { format: false }
714
+ end
464
715
  end
465
716
  ```
466
717
 
467
718
  simplifications (version >= 2.1 is required):
468
719
 
469
720
  ```ruby
470
- create_table :table_name do |t|
471
- t.string :contains_word, format: /word/
472
- t.string :contains_word_in_trigger, format: { with: /word/, as: :trigger }
721
+ def change
722
+ create_table :table_name do |t|
723
+ t.string :contains_word, format: /word/
724
+ t.string :contains_word_in_trigger, format: { with: /word/,
725
+ as: :trigger }
726
+ end
473
727
  end
474
728
  ```
475
729
 
@@ -484,60 +738,92 @@ allow `NULL`:
484
738
  * `allow_blank` - ignore validation for blank values. Default value: `false`
485
739
  * `as` - defines the way how constraint will be implemented. Possible values: `[:trigger, :check]` Default value: `:check`
486
740
 
487
- ### custom (version >= 2.1 is required)
741
+ ### custom
742
+
743
+ (version >= 2.1 is required)
488
744
 
489
745
  Examples:
490
746
 
491
747
  allows only values that contains 'word' inside:
492
748
 
493
749
  ```ruby
494
- validates :table_name, :column_name,
495
- custom: { statement: "TRIM({column_name}) ~ 'word'" }
750
+ def up
751
+ validates :table_name, :column_name,
752
+ custom: { statement: "TRIM({column_name}) ~ 'word'" }
753
+ end
754
+
755
+ def down
756
+ validates :table_name, :column_name, custom: false
757
+ end
496
758
  ```
497
759
 
498
760
  with failure message:
499
761
 
500
762
  ```ruby
501
- validates :table_name, :column_name,
502
- custom: { statement: "TRIM({column_name}) ~ 'word'",
503
- message: 'Column_name value should contain start word' }
763
+ def up
764
+ validates :table_name, :column_name,
765
+ custom: { statement: "TRIM({column_name}) ~ 'word'",
766
+ message: 'Column_name value should contain start word' }
767
+ end
768
+
769
+ def down
770
+ validates :table_name, :column_name, custom: false
771
+ end
504
772
  ```
505
773
 
506
774
  implemented as trigger:
507
775
 
508
776
  ```ruby
509
- validates :table_name, :column_name,
510
- custom: { statement: "TRIM({column_name}) ~ 'word'",
511
- message: 'Column_name value should contain start word',
512
- as: :trigger }
777
+ def up
778
+ validates :table_name, :column_name,
779
+ custom: { statement: "TRIM({column_name}) ~ 'word'",
780
+ message: 'Column_name value should contain start word',
781
+ as: :trigger }
782
+ end
783
+
784
+ def down
785
+ validates :table_name, :column_name, custom: false
786
+ end
513
787
  ```
514
788
 
515
789
  all above are available in a create and change table blocks:
516
790
 
517
791
  ```ruby
518
- create_table :table_name do |t|
519
- t.string :column_name,
792
+ def change
793
+ create_table :table_name do |t|
794
+ t.string :column_name,
520
795
  validates: { custom: { statement: "TRIM({column_name}) ~ 'word'"} }
796
+ end
521
797
  end
522
798
  ```
523
799
 
524
800
  ```ruby
525
- change :table_name do |t|
526
- t.change :column_name, :string,
801
+ def up
802
+ change :table_name do |t|
803
+ t.change :column_name, :string,
527
804
  validates: { custom: { statement: "TRIM({column_name}) ~ 'word'"} }
805
+ end
806
+ end
807
+
808
+ def down
809
+ change :table_name do |t|
810
+ t.change :column_name, :string, validates: { custom: false }
811
+ end
528
812
  end
529
813
  ```
530
814
 
531
815
  simplifications (version >= 2.1 is required):
532
816
 
533
817
  ```ruby
534
- create_table :table_name do |t|
535
- t.string :contains_word, custom: "TRIM({contains_word}) ~ 'word'"
536
- t.string :contains_word_synonym,
537
- validates: "TRIM({contains_word_synonym}) ~ 'word'"
538
- t.string :contains_word_in_trigger,
539
- custom: { statement: "TRIM({contains_word_in_trigger}) ~ 'word'",
540
- as: :trigger }
818
+ def change
819
+ create_table :table_name do |t|
820
+ t.string :contains_word, custom: "TRIM({contains_word}) ~ 'word'"
821
+ t.string :contains_word_synonym,
822
+ validates: "TRIM({contains_word_synonym}) ~ 'word'"
823
+ t.string :contains_word_in_trigger,
824
+ custom: { statement: "TRIM({contains_word_in_trigger}) ~ 'word'",
825
+ as: :trigger }
826
+ end
541
827
  end
542
828
  ```
543
829
 
@@ -552,8 +838,22 @@ allow `NULL`:
552
838
  * `allow_blank` - ignore validation for blank values. Default value: `false`
553
839
  * `as` - defines the way how constraint will be implemented. Possible values: `[:trigger, :check]` Default value: `:check`
554
840
 
555
- ## Contributing to mv-postgresql
556
-
841
+ ## Version History
842
+
843
+ **(2.0.0)** (17 Jan, 2015)
844
+
845
+ * Completely rewritten. Migrated to Ruby 2.0 and RoR 4
846
+
847
+ **(2.1.0)** (22 Jan, 2015)
848
+
849
+ * Custom validation
850
+
851
+ **(2.2.0)** (28 Jan, 2015)
852
+
853
+ * Integration with ActiveRecord
854
+
855
+ ## Contributing
856
+
557
857
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
558
858
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
559
859
  * Fork the project
@@ -562,8 +862,3 @@ allow `NULL`:
562
862
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
563
863
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
564
864
 
565
- ## Copyright
566
-
567
- Copyright (c) 2011 Valeriy Prokopchuk. See LICENSE.txt for
568
- further details.
569
-
@@ -25,6 +25,8 @@ require 'mv/postgresql/validation/builder/trigger/absence'
25
25
  require 'mv/postgresql/validation/builder/trigger/uniqueness'
26
26
  require 'mv/postgresql/validation/builder/trigger/custom'
27
27
 
28
+ require 'mv/postgresql/validation/active_model_presenter/format'
29
+
28
30
  ActiveSupport.on_load(:mv_core) do
29
31
  #router
30
32
  Mv::Core::Router.define_route(:check, Mv::Postgresql::Route::Check)
@@ -72,5 +74,15 @@ ActiveSupport.on_load(:mv_core) do
72
74
  Mv::Postgresql::Validation::Custom => Mv::Core::Validation::Builder::Custom
73
75
  )
74
76
 
77
+ #validation active model presenters
78
+ Mv::Core::Validation::ActiveModelPresenter::Factory.register_presenters(
79
+ Mv::Postgresql::Validation::Exclusion => Mv::Core::Validation::ActiveModelPresenter::Exclusion,
80
+ Mv::Postgresql::Validation::Inclusion => Mv::Core::Validation::ActiveModelPresenter::Inclusion,
81
+ Mv::Postgresql::Validation::Length => Mv::Core::Validation::ActiveModelPresenter::Length,
82
+ Mv::Postgresql::Validation::Presence => Mv::Core::Validation::ActiveModelPresenter::Presence,
83
+ Mv::Postgresql::Validation::Absence => Mv::Core::Validation::ActiveModelPresenter::Absence,
84
+ Mv::Postgresql::Validation::Format => Mv::Postgresql::Validation::ActiveModelPresenter::Format
85
+ )
86
+
75
87
  end
76
88
 
@@ -0,0 +1,17 @@
1
+ module Mv
2
+ module Postgresql
3
+ module Validation
4
+ module ActiveModelPresenter
5
+ class Format < Mv::Core::Validation::ActiveModelPresenter::Base
6
+ def option_names
7
+ super + [:with]
8
+ end
9
+
10
+ def validation_name
11
+ :format
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mv-postgresql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.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-22 00:00:00.000000000 Z
11
+ date: 2015-01-28 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.1'
47
+ version: '2.2'
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.1'
54
+ version: '2.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: jeweler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +140,7 @@ files:
140
140
  - lib/mv/postgresql/railtie.rb
141
141
  - lib/mv/postgresql/route/check.rb
142
142
  - lib/mv/postgresql/validation/absence.rb
143
+ - lib/mv/postgresql/validation/active_model_presenter/format.rb
143
144
  - lib/mv/postgresql/validation/builder/exclusion.rb
144
145
  - lib/mv/postgresql/validation/builder/format.rb
145
146
  - lib/mv/postgresql/validation/builder/inclusion.rb
@@ -171,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
172
  requirements:
172
173
  - - '>='
173
174
  - !ruby/object:Gem::Version
174
- version: '0'
175
+ version: '2.0'
175
176
  required_rubygems_version: !ruby/object:Gem::Requirement
176
177
  requirements:
177
178
  - - '>='