valhammer 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/valhammer/configuration.rb +14 -0
- data/lib/valhammer/validations.rb +4 -4
- data/lib/valhammer/version.rb +1 -1
- data/lib/valhammer.rb +6 -3
- data/spec/lib/valhammer/validations_spec.rb +52 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a5c5adbed9b66cb80eb994a6d9595a56cbf1de28e0f105b5440687a53805c63
|
4
|
+
data.tar.gz: b94ce0e81bfe18c2ba9f85967aa29b0facc3433357694304189d8e1c9ce43d2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38d4db5e578d88ea9ad8f23a411a0a1edfa32366fdbbcc3ced400c6414750dfcb8d929b6ae29a9a46b898d2596217e1784c446eca8f1bf42c1feb818c58d2518
|
7
|
+
data.tar.gz: 83898470fcc987c4f81d71b2d302ff0f327dd19241b04bd3afd3bd45003bedcf3b22b898767a6ce28f73ae643c0fe9ad031529d58f334cf3899004405fedc8e4
|
data/README.md
CHANGED
@@ -264,6 +264,14 @@ end
|
|
264
264
|
In this case, it is not possible for valhammer to determine the behaviour of the
|
265
265
|
`where` clause, so the validation must be manually created.
|
266
266
|
|
267
|
+
## Logging
|
268
|
+
|
269
|
+
To make Valhammer tell you exactly what it's doing, turn on verbose mode:
|
270
|
+
|
271
|
+
```ruby
|
272
|
+
Valhammer.config.verbose = true
|
273
|
+
```
|
274
|
+
|
267
275
|
## Contributing
|
268
276
|
|
269
277
|
Refer to [GitHub Flow](https://guides.github.com/introduction/flow/) for
|
@@ -64,8 +64,6 @@ module Valhammer
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def valhammer_validations(column, opts)
|
67
|
-
logger.debug("Valhammer generating options for #{valhammer_info(column)}")
|
68
|
-
|
69
67
|
validations = {}
|
70
68
|
valhammer_presence(validations, column, opts)
|
71
69
|
valhammer_inclusion(validations, column, opts)
|
@@ -73,8 +71,10 @@ module Valhammer
|
|
73
71
|
valhammer_numeric(validations, column, opts)
|
74
72
|
valhammer_length(validations, column, opts)
|
75
73
|
|
76
|
-
|
77
|
-
|
74
|
+
if Valhammer.config.verbose?
|
75
|
+
logger.debug("Valhammer options for #{valhammer_log_key(column)} " \
|
76
|
+
"are: #{validations.inspect}")
|
77
|
+
end
|
78
78
|
validations
|
79
79
|
end
|
80
80
|
|
data/lib/valhammer/version.rb
CHANGED
data/lib/valhammer.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'valhammer/version'
|
2
|
+
require 'valhammer/configuration'
|
3
|
+
require 'valhammer/validations'
|
4
|
+
require 'valhammer/railtie' if defined?(Rails::Railtie)
|
2
5
|
|
3
6
|
module Valhammer
|
7
|
+
def self.config
|
8
|
+
Configuration.instance
|
9
|
+
end
|
4
10
|
end
|
5
|
-
|
6
|
-
require 'valhammer/validations'
|
7
|
-
require 'valhammer/railtie' if defined?(Rails::Railtie)
|
@@ -291,6 +291,58 @@ RSpec.describe Valhammer::Validations do
|
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|
294
|
+
describe 'logging' do
|
295
|
+
before do
|
296
|
+
hammerable =
|
297
|
+
Class.new(ActiveRecord::Base) do
|
298
|
+
self.table_name = :organisations
|
299
|
+
end
|
300
|
+
|
301
|
+
def self.logger
|
302
|
+
# Hook for specs to spy on log output
|
303
|
+
end
|
304
|
+
|
305
|
+
stub_const 'Hammerable', hammerable
|
306
|
+
end
|
307
|
+
|
308
|
+
context 'when verbose' do
|
309
|
+
around do |example|
|
310
|
+
Valhammer.config.verbose = true
|
311
|
+
example.run
|
312
|
+
ensure
|
313
|
+
Valhammer.config.verbose = false
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'logs information about validations' do
|
317
|
+
logger = spy(:debug)
|
318
|
+
allow(Hammerable).to receive(:logger).and_return(logger)
|
319
|
+
|
320
|
+
Hammerable.valhammer
|
321
|
+
|
322
|
+
expect(logger).to have_received(:debug).with(
|
323
|
+
'Valhammer options for `organisations`.`name` are: {:presence=>true}'
|
324
|
+
)
|
325
|
+
expect(logger).to have_received(:debug).with(
|
326
|
+
'Valhammer options for `organisations`.`country` are: {:presence=>true}'
|
327
|
+
)
|
328
|
+
expect(logger).to have_received(:debug).with(
|
329
|
+
'Valhammer options for `organisations`.`city` are: {:presence=>true}'
|
330
|
+
)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
context 'when quiet' do
|
335
|
+
it 'does not log' do
|
336
|
+
logger = spy(:debug)
|
337
|
+
allow(Hammerable).to receive(:logger).and_return(logger)
|
338
|
+
|
339
|
+
Hammerable.valhammer
|
340
|
+
|
341
|
+
expect(logger).not_to have_received(:debug)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
294
346
|
context 'sanity check' do
|
295
347
|
let(:organisation) do
|
296
348
|
Organisation.create!(name: 'Enhanced Collaborative Methodologies Pty Ltd',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valhammer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shaun Mangelsdorf
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -192,7 +192,7 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
-
description:
|
195
|
+
description:
|
196
196
|
email:
|
197
197
|
- s.mangelsdorf@gmail.com
|
198
198
|
executables: []
|
@@ -209,6 +209,7 @@ files:
|
|
209
209
|
- README.md
|
210
210
|
- Rakefile
|
211
211
|
- lib/valhammer.rb
|
212
|
+
- lib/valhammer/configuration.rb
|
212
213
|
- lib/valhammer/railtie.rb
|
213
214
|
- lib/valhammer/validations.rb
|
214
215
|
- lib/valhammer/version.rb
|
@@ -229,7 +230,7 @@ homepage: https://github.com/ausaccessfed/valhammer
|
|
229
230
|
licenses:
|
230
231
|
- Apache-2.0
|
231
232
|
metadata: {}
|
232
|
-
post_install_message:
|
233
|
+
post_install_message:
|
233
234
|
rdoc_options: []
|
234
235
|
require_paths:
|
235
236
|
- lib
|
@@ -244,8 +245,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
244
245
|
- !ruby/object:Gem::Version
|
245
246
|
version: '0'
|
246
247
|
requirements: []
|
247
|
-
rubygems_version: 3.
|
248
|
-
signing_key:
|
248
|
+
rubygems_version: 3.3.7
|
249
|
+
signing_key:
|
249
250
|
specification_version: 4
|
250
251
|
summary: Automatically validate ActiveRecord models based on the database schema.
|
251
252
|
test_files:
|