mv-sqlite 2.0.1 → 2.1.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: f3d48d624d459a19608b840d2fc0bfdd69c5ef4f
4
- data.tar.gz: c1f29635fa7ad0309419479c5902db904f8ff159
3
+ metadata.gz: 041135708ece1d93dd74c9f9d6ab910a36113a24
4
+ data.tar.gz: 0c1ccb017f85ed3b76cfc35d3f523a06c991f375
5
5
  SHA512:
6
- metadata.gz: 2fca15126f81cbd55c63818a09617b8b13f70003e85b53474aa2bf2764cbd128ceb3ddfc24e0d83dc37be15d99a71ad1e399678b3cffe09479b4eea013ac521f
7
- data.tar.gz: 6f2b3c63d64092341038f2f033e2799e0763cf65e16b66e4bae2106479c639f87832f40aec61ad28c1cf742b93c785e235bf5341c7a5fd5b8cb75f822967431d
6
+ metadata.gz: b77f5f0d7851d9e524ef85b8134bac98bec4c9b6ed6a5d7b1276ce2f3ecaa450a757c7fcc78e93a89eae6307faae4ec9e101d8c8fdcfb1cbe50d47764a762205
7
+ data.tar.gz: 66235c8f42816eff1c18d2fea5451a453f9ab665d37c44c73ae8c1a34b73b0ad5da269c95eb89d34ec92f90c0491db8b35f2d317fba3cb22cb45d0f24cbb59d8
data/README.md CHANGED
@@ -1,11 +1,10 @@
1
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/vprokopchuk256/mv-sqlite/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
2
1
  [![Build Status](https://travis-ci.org/vprokopchuk256/mv-sqlite.svg)](https://travis-ci.org/vprokopchuk256/mv-sqlite)
3
2
  [![Coverage Status](https://coveralls.io/repos/vprokopchuk256/mv-sqlite/badge.png?branch=master)](https://coveralls.io/r/vprokopchuk256/mv-sqlite?branch=master)
4
3
  [![Gem Version](https://badge.fury.io/rb/mv-sqlite.svg)](http://badge.fury.io/rb/mv-sqlite)
5
4
 
6
5
  # Introduction
7
6
 
8
- mv-sqlite is the SQLite driver for Migration Validators project (details here: https://github.com/vprokopchuk256/mv-core)
7
+ mv-sqlite is the SQLite 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
 
@@ -14,12 +13,12 @@ mv-sqlite is the SQLite driver for Migration Validators project (details here: h
14
13
  Examples:
15
14
 
16
15
  validate uniqueness of the column 'column_name':
17
-
16
+
18
17
  ```ruby
19
18
  validates :table_name, :column_name, uniqueness: true
20
19
  ```
21
20
 
22
- define validation as trigger with spefified failure message:
21
+ define validation as trigger with specified failure message:
23
22
 
24
23
  ```ruby
25
24
  validates :table_name, :column_name,
@@ -42,7 +41,15 @@ mv-sqlite is the SQLite driver for Migration Validators project (details here: h
42
41
 
43
42
  ```ruby
44
43
  change :table_name do |t|
45
- t.change :column_name, :string, validates: { uniqueness: false }
44
+ t.change :column_name, :string, :validates: { uniqueness: false }
45
+ end
46
+ ```
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
46
53
  end
47
54
  ```
48
55
 
@@ -59,17 +66,17 @@ mv-sqlite is the SQLite driver for Migration Validators project (details here: h
59
66
 
60
67
  ### length
61
68
 
62
- Examples:
69
+ Examples:
63
70
 
64
71
  column value length should be more than 4 symbols and less than 9. Otherwise 'Wrong length message' error will be raised:
65
72
 
66
- ```ruby
73
+ ```ruby
67
74
  validates :table_name, :column_name,
68
75
  length: { in: 5..8,
69
76
  message: 'Wrong length message' }
70
- ```
77
+ ```
71
78
 
72
- allow `NULL`:
79
+ allow `NULL`:
73
80
 
74
81
  ```ruby
75
82
  validates :table_name, :column_name,
@@ -80,8 +87,34 @@ mv-sqlite is the SQLite driver for Migration Validators project (details here: h
80
87
 
81
88
  ```ruby
82
89
  validates :table_name, :column_name,
83
- length: { maximum: 3,
84
- too_long: 'Value is longer than 3 symbols' }
90
+ length: { maximum: 3,
91
+ too_long: 'Value is longer than 3 symbols' }
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
85
118
  ```
86
119
 
87
120
  Options:
@@ -103,20 +136,45 @@ mv-sqlite is the SQLite driver for Migration Validators project (details here: h
103
136
 
104
137
  ### inclusion
105
138
 
106
- Examples:
139
+ Examples:
107
140
 
108
- valid values array:
141
+ valid values array:
109
142
 
110
143
  ```ruby
111
144
  validates :table_name, :column_name, inclusion: { in: [1, 2, 3] }
112
145
  ```
113
146
 
114
- with failure message specified:
147
+ with failure message specified:
115
148
 
116
149
  ```ruby
117
150
  validates :table_name, :column_name,
118
- inclusion: { in: [1, 2, 3],
119
- message: "Column 'column_name' should be equal to 1 or 2 or 3" }
151
+ inclusion: { in: [1, 2, 3],
152
+ message: "Column 'column_name' should be equal to 1 or 2 or 3" }
153
+ ```
154
+
155
+ all above are available in a create and change table blocks:
156
+
157
+ ```ruby
158
+ create_table :table_name do |t|
159
+ t.integer :column_name, validates: { inclusion: { in: 1..3 } }
160
+ end
161
+ ```
162
+
163
+ ```ruby
164
+ change :table_name do |t|
165
+ t.change :column_name, :integer, validates: { inclusion: { in: 1..3 } }
166
+ end
167
+ ```
168
+
169
+ simplifications (version >= 2.1 is required):
170
+
171
+ ```ruby
172
+ create_table :table_name do |t|
173
+ t.string :str_or_str_1, inclusion: ['str', 'str1']
174
+ t.string :from_str_to_str_1, inclusion: 'str'..'str1'
175
+ t.string :str_or_str_1_in_trigger, inclusion: { in: ['str', 'str1'],
176
+ as: :trigger}
177
+ end
120
178
  ```
121
179
 
122
180
  Options:
@@ -133,27 +191,46 @@ mv-sqlite is the SQLite driver for Migration Validators project (details here: h
133
191
 
134
192
  ### exclusion
135
193
 
136
- exclude 1, 2, and 3:
194
+ Examples:
195
+
196
+ exclude 1, 2, and 3:
137
197
 
138
198
  ```ruby
139
199
  validates :table_name, :column_name, exclusion: { in: [1, 2, 3] }
140
200
  ```
141
201
 
142
- exclude values with specified failure message:
202
+ the same with failure message:
143
203
 
144
204
  ```ruby
145
205
  validates :table_name, :column_name,
146
- exclusion: {
206
+ exclusion: {
147
207
  in: [1, 2, 3],
148
- message: "Column 'column_name' should not be equal to 1 or 2 or 3"
149
- }
208
+ message: "Column 'column_name' should not be equal to 1 or 2 or 3" }
150
209
  ```
151
210
 
152
- performs verification on update only:
211
+ all above are available in a create and change table blocks:
153
212
 
154
213
  ```ruby
155
- validates :table_name, :column_name, exclusion: { in: [1, 2, 3],
156
- on: :update }
214
+ create_table :table_name do |t|
215
+ t.integer :column_name, validates: { exclusion: { in: 1..3 } }
216
+ end
217
+ ```
218
+
219
+ ```ruby
220
+ change :table_name do |t|
221
+ t.change :column_name, :integer, validates: { exclusion: { in: 1..3 } }
222
+ end
223
+ ```
224
+
225
+ simplifications (version >= 2.1 is required):
226
+
227
+ ```ruby
228
+ create_table :table_name do |t|
229
+ t.string :neither_str_nor_str_1, exclusion: ['str', 'str1']
230
+ t.string :from_str_to_str_1, exclusion: 'str'..'str1'
231
+ t.string :str_or_str_1_in_trigger, exclusion: { in: ['str', 'str1'],
232
+ as: :trigger}
233
+ end
157
234
  ```
158
235
 
159
236
  Options:
@@ -171,8 +248,6 @@ mv-sqlite is the SQLite driver for Migration Validators project (details here: h
171
248
 
172
249
  Examples:
173
250
 
174
- simple presence validator:
175
-
176
251
  ```ruby
177
252
  validates :table_name, :column_name, presence: true
178
253
  ```
@@ -181,17 +256,41 @@ mv-sqlite is the SQLite driver for Migration Validators project (details here: h
181
256
 
182
257
  ```ruby
183
258
  validates :table_name, :column_name,
184
- presence: { message: 'value should not be empty' }
259
+ presence: { message: 'value should not be empty' }
185
260
  ```
186
261
 
187
- performs verification only when new record is inserted:
262
+ check when record is inserted only:
188
263
 
189
264
  ```ruby
190
265
  validates :table_name, :column_name,
191
266
  presence: { message: 'value should not be empty',
267
+ as: :trigger,
192
268
  on: :create }
193
269
  ```
194
270
 
271
+ all above are available in a create and change table blocks:
272
+
273
+ ```ruby
274
+ create_table :table_name do |t|
275
+ t.string :column_name, validates: { presence: true }
276
+ end
277
+ ```
278
+
279
+ ```ruby
280
+ change :table_name do |t|
281
+ t.change :column_name, :string, validates: { presence: true }
282
+ end
283
+ ```
284
+
285
+ simplifications (version >= 2.1 is required):
286
+
287
+ ```ruby
288
+ create_table :table_name do |t|
289
+ t.string :presence_in_check, presence: true
290
+ t.string :presence_in_trigger, presence: { as: :trigger, on: :create }
291
+ end
292
+ ```
293
+
195
294
  Options:
196
295
 
197
296
  * `:message` - message that should be shown if validation failed
@@ -206,8 +305,6 @@ mv-sqlite is the SQLite driver for Migration Validators project (details here: h
206
305
 
207
306
  Examples:
208
307
 
209
- simple absence validator:
210
-
211
308
  ```ruby
212
309
  validates :table_name, :column_name, absence: true
213
310
  ```
@@ -216,17 +313,98 @@ mv-sqlite is the SQLite driver for Migration Validators project (details here: h
216
313
 
217
314
  ```ruby
218
315
  validates :table_name, :column_name,
219
- absence: { message: 'value should be empty' }
316
+ absence: { message: 'value should be empty' }
220
317
  ```
221
318
 
222
- performs verification only when new record is inserted:
319
+ check when record is inserted only:
223
320
 
224
321
  ```ruby
225
322
  validates :table_name, :column_name,
226
323
  absence: { message: 'value should be empty',
227
- on: :create }
324
+ as: :trigger,
325
+ on: :create }
326
+ ```
327
+
328
+ all above are available in a create and change table blocks:
329
+
330
+ ```ruby
331
+ create_table :table_name do |t|
332
+ t.string :column_name, validates: { absence: true }
333
+ end
334
+ ```
335
+
336
+ ```ruby
337
+ change :table_name do |t|
338
+ t.change :column_name, :string, validates: { absence: true }
339
+ end
228
340
  ```
229
341
 
342
+ simplifications (version >= 2.1 is required):
343
+
344
+ ```ruby
345
+ create_table :table_name do |t|
346
+ t.string :absence_in_check, absence: true
347
+ t.string :absence_in_trigger, absence: { as: :trigger, on: :create }
348
+ end
349
+ ```
350
+
351
+ ### custom (version >= 2.1 is required)
352
+
353
+ Examples:
354
+
355
+ allows only values that equals 'word' when trimmed:
356
+
357
+ ```ruby
358
+ validates :table_name, :column_name,
359
+ custom: { statement: "TRIM({column_name}) = 'word'" }
360
+ ```
361
+
362
+ with failure message:
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
+ ```
369
+
370
+ implemented as trigger on insert event:
371
+
372
+ ```ruby
373
+ validates :table_name, :column_name,
374
+ custom: { statement: "TRIM({column_name}) = 'word'",
375
+ message: 'Column_name value should contain start word',
376
+ as: :trigger,
377
+ on: :create }
378
+ ```
379
+
380
+ all above are available in a create and change table blocks:
381
+
382
+ ```ruby
383
+ create_table :table_name do |t|
384
+ t.string :column_name,
385
+ validates: { custom: { statement: "TRIM({column_name}) = 'word'"} }
386
+ end
387
+ ```
388
+
389
+ ```ruby
390
+ change :table_name do |t|
391
+ t.change :column_name, :string,
392
+ validates: { custom: { statement: "TRIM({column_name}) = 'word'"} }
393
+ end
394
+ ```
395
+
396
+ simplifications (version >= 2.1 is required):
397
+
398
+ ```ruby
399
+ create_table :table_name do |t|
400
+ t.string :contains_word, custom: "TRIM({contains_word}) = 'word'"
401
+ t.string :contains_word_synonym,
402
+ validates: "TRIM({contains_word_synonym}) = 'word'"
403
+ t.string :contains_word_in_trigger,
404
+ custom: { statement: "TRIM({contains_word_in_trigger}) = 'word'", as: :trigger }
405
+ end
406
+ ```
407
+
230
408
  Options:
231
409
 
232
410
  * `:message` - message that should be shown if validation failed
data/lib/mv-sqlite.rb CHANGED
@@ -9,6 +9,7 @@ require 'mv/sqlite/validation/builder/trigger/length'
9
9
  require 'mv/sqlite/validation/builder/trigger/presence'
10
10
  require 'mv/sqlite/validation/builder/trigger/absence'
11
11
  require 'mv/sqlite/validation/builder/trigger/uniqueness'
12
+ require 'mv/sqlite/validation/builder/trigger/custom'
12
13
 
13
14
  ActiveSupport.on_load(:mv_core) do
14
15
 
@@ -24,7 +25,8 @@ ActiveSupport.on_load(:mv_core) do
24
25
  Mv::Core::Validation::Length => Mv::Sqlite::Validation::Builder::Trigger::Length,
25
26
  Mv::Core::Validation::Presence => Mv::Sqlite::Validation::Builder::Trigger::Presence,
26
27
  Mv::Core::Validation::Absence => Mv::Sqlite::Validation::Builder::Trigger::Absence,
27
- Mv::Core::Validation::Uniqueness => Mv::Sqlite::Validation::Builder::Trigger::Uniqueness
28
+ Mv::Core::Validation::Uniqueness => Mv::Sqlite::Validation::Builder::Trigger::Uniqueness,
29
+ Mv::Core::Validation::Custom => Mv::Sqlite::Validation::Builder::Trigger::Custom
28
30
  )
29
31
  end
30
32
 
@@ -0,0 +1,15 @@
1
+ require 'mv/sqlite/validation/builder/trigger/trigger_column'
2
+
3
+ module Mv
4
+ module Sqlite
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mv-sqlite
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
@@ -123,6 +123,7 @@ files:
123
123
  - lib/mv/sqlite/constraint/builder/trigger.rb
124
124
  - lib/mv/sqlite/railtie.rb
125
125
  - lib/mv/sqlite/validation/builder/trigger/absence.rb
126
+ - lib/mv/sqlite/validation/builder/trigger/custom.rb
126
127
  - lib/mv/sqlite/validation/builder/trigger/exclusion.rb
127
128
  - lib/mv/sqlite/validation/builder/trigger/inclusion.rb
128
129
  - lib/mv/sqlite/validation/builder/trigger/length.rb