sanitization 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -1
- data/lib/sanitization.rb +3 -3
- data/lib/{active_record/sanitization.rb → sanitization/active_record_extension.rb} +8 -7
- data/lib/sanitization/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c204e5917662144318c424b310a9ad6c8bdd64d59a421086fadd8bc94a48e239
|
4
|
+
data.tar.gz: 5cbe00e349e72aa1e12371cc8155b1e2c80288b3da6ff0286665cdddfd7a0c1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaafc40ec8fdddd782b913830f83a488974dafedab9c10004e61bc40209ee40e61112bff9d872c38deefede278f200f1e258dced084f720f4c730e7f99e2f4a8
|
7
|
+
data.tar.gz: 1f1e095ce608ac8da583760efb546364dfe707c0c884c91541ceb364015b632cfd6695117153519e42221673fc54db7852ab9c06a59f26234b1ef44393a39193
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -13,6 +13,7 @@ Sanitization makes it easy to store slightly cleaner strings to your database.
|
|
13
13
|
|
14
14
|
- Leading & training white spaces are stripped (`strip: true`)
|
15
15
|
- All spaces are collapsed (`collapse: true`)
|
16
|
+
- All empty strings are stored as `null` if the database column allows it (`nullify: true`)
|
16
17
|
- All String columns are sanitized (`only: nil, except: nil`)
|
17
18
|
- Columns of type `text` are not sanitized (`include_text_type: false`)
|
18
19
|
- Casing remains unchanged (`case: nil`)
|
@@ -24,6 +25,7 @@ Sanitization makes it easy to store slightly cleaner strings to your database.
|
|
24
25
|
bundle add sanitization
|
25
26
|
```
|
26
27
|
|
28
|
+
|
27
29
|
## Usage
|
28
30
|
|
29
31
|
```ruby
|
@@ -62,7 +64,8 @@ class Person
|
|
62
64
|
sanitization only: :do_not_collapse, collapse: false
|
63
65
|
|
64
66
|
# Sanitize with a custom casing method named `leetcase` for the `133t` column.
|
65
|
-
|
67
|
+
# Don't nullify empty strings.
|
68
|
+
sanitization only: '1337', case: :leet, nullify: false
|
66
69
|
end
|
67
70
|
|
68
71
|
```
|
data/lib/sanitization.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require "sanitization/version"
|
2
|
-
require "
|
2
|
+
require "sanitization/active_record_extension"
|
3
|
+
require "active_record" unless defined?(ActiveRecord)
|
3
4
|
|
4
5
|
module Sanitization
|
5
6
|
class Error < StandardError; end
|
6
7
|
end
|
7
8
|
|
8
9
|
ActiveRecord::Base.class_eval do
|
9
|
-
include
|
10
|
+
include Sanitization::ActiveRecordExtension
|
10
11
|
end
|
11
|
-
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module Sanitization
|
1
|
+
module Sanitization
|
2
|
+
module ActiveRecordExtension
|
5
3
|
def self.append_features(base)
|
6
4
|
super
|
7
5
|
base.extend(ClassMethods)
|
@@ -12,6 +10,9 @@ module ActiveRecord
|
|
12
10
|
|
13
11
|
private
|
14
12
|
def sanitization(options = {})
|
13
|
+
# Skip initialization if table is not yet created. For example, during migrations.
|
14
|
+
return unless ActiveRecord::Base.connection.data_source_exists?(self.table_name)
|
15
|
+
|
15
16
|
self.sanitization__store ||= {}
|
16
17
|
|
17
18
|
options[:only] = Array.wrap(options[:only])
|
@@ -50,7 +51,7 @@ module ActiveRecord
|
|
50
51
|
end
|
51
52
|
|
52
53
|
class_eval <<-EOV
|
53
|
-
include
|
54
|
+
include Sanitization::ActiveRecordExtension::InstanceMethods
|
54
55
|
before_save :sanitization__format_strings
|
55
56
|
EOV
|
56
57
|
end
|
@@ -115,6 +116,6 @@ module ActiveRecord
|
|
115
116
|
|
116
117
|
|
117
118
|
end # module InstanceMethods
|
118
|
-
end # module
|
119
|
-
end # module
|
119
|
+
end # module ActiveRecordExt
|
120
|
+
end # module Sanitization
|
120
121
|
|
data/lib/sanitization/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanitization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Mercier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -54,8 +54,8 @@ files:
|
|
54
54
|
- Rakefile
|
55
55
|
- bin/console
|
56
56
|
- bin/setup
|
57
|
-
- lib/active_record/sanitization.rb
|
58
57
|
- lib/sanitization.rb
|
58
|
+
- lib/sanitization/active_record_extension.rb
|
59
59
|
- lib/sanitization/version.rb
|
60
60
|
- sanitization.gemspec
|
61
61
|
homepage: https://github.com/cmer/sanitization
|