sanitization 1.0.0 → 1.0.2

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
  SHA256:
3
- metadata.gz: 380311ca85432700d4426ddb1a6a6e42daa861206d22954a686b4453ef385bff
4
- data.tar.gz: 8cf63d1d494492d6859a3d97b1e61cfa6921941f4527d0acb7a0ef3b364d5060
3
+ metadata.gz: c204e5917662144318c424b310a9ad6c8bdd64d59a421086fadd8bc94a48e239
4
+ data.tar.gz: 5cbe00e349e72aa1e12371cc8155b1e2c80288b3da6ff0286665cdddfd7a0c1e
5
5
  SHA512:
6
- metadata.gz: f30635f856767f472f4761ffa213043fdcaed98b80129c27862f2bd5295fa7402a87e178b2dfbaffae5848d8ebf27ea5fd2211dd044cc269ceb66b40c2342ac5
7
- data.tar.gz: 331210228d4cca1c382b7ffd0719735d3e65d42b50480ea51448de466bc9c9d2498bdbb42a980648d0b15abbfef36b2d9c3db4c3502b80c1c6c04e0f19adb6be
6
+ metadata.gz: eaafc40ec8fdddd782b913830f83a488974dafedab9c10004e61bc40209ee40e61112bff9d872c38deefede278f200f1e258dced084f720f4c730e7f99e2f4a8
7
+ data.tar.gz: 1f1e095ce608ac8da583760efb546364dfe707c0c884c91541ceb364015b632cfd6695117153519e42221673fc54db7852ab9c06a59f26234b1ef44393a39193
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sanitization (1.0.0)
4
+ sanitization (1.0.2)
5
5
  activerecord
6
6
  activesupport
7
7
 
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
- sanitization only: '1337', case: :leet
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 "active_record/sanitization"
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 ActiveRecord::Sanitization
10
+ include Sanitization::ActiveRecordExtension
10
11
  end
11
-
@@ -1,7 +1,5 @@
1
- require 'active_record'
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 ActiveRecord::Sanitization::InstanceMethods
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 Sanitization
119
- end # module ActiveRecord
119
+ end # module ActiveRecordExt
120
+ end # module Sanitization
120
121
 
@@ -1,3 +1,3 @@
1
1
  module Sanitization
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
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.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-03 00:00:00.000000000 Z
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