auto_strip_attributes 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/CHANGELOG.md +4 -0
- data/README.md +9 -9
- data/lib/auto_strip_attributes.rb +2 -1
- data/lib/auto_strip_attributes/version.rb +1 -1
- data/test/auto_strip_attributes_test.rb +3 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7f41d4c8204a70a3b6fc653418a3369d737fbdd
|
4
|
+
data.tar.gz: b20036dddc63af1f43273efec0328801bd116896
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2add7072f56073876aaedb9cfd2ebbb30323edcbb4a3693660c1193a37cc27c779ea1f771526b82a13299f4aeb637b3833630707ecfbdf00f96f27ff33c67d83
|
7
|
+
data.tar.gz: de8aa50ac43b6bec22a230dca3403311279d4ee57cb9c8e71a03c1b52e8037e24d664d5aafff47ead7b2f754917edc098a9e492498928eae81a4eecacc7e89c5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## [Master]
|
2
2
|
|
3
|
+
## [2.3] - 2018-02-06
|
4
|
+
|
5
|
+
- Replacing all utf8 characters in squish (thnks to [@nasa42](https://github.com/holli/auto_strip_attributes/pull/24))
|
6
|
+
|
3
7
|
## [2.2] - 2016-07-28
|
4
8
|
|
5
9
|
- Added 'virtual'-option (thnks to [@nasa42](https://github.com/holli/auto_strip_attributes/pull/23))
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Gem has option to set empty strings to nil or to remove extra spaces inside the
|
|
16
16
|
Include gem in your Gemfile:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem "auto_strip_attributes", "~> 2.
|
19
|
+
gem "auto_strip_attributes", "~> 2.3"
|
20
20
|
```
|
21
21
|
|
22
22
|
```ruby
|
@@ -26,10 +26,10 @@ class User < ActiveRecord::Base
|
|
26
26
|
auto_strip_attributes :nick, :comment
|
27
27
|
|
28
28
|
# Squeezes spaces inside the string: "James Bond " => "James Bond"
|
29
|
-
auto_strip_attributes :name, :
|
29
|
+
auto_strip_attributes :name, squish: true
|
30
30
|
|
31
31
|
# Won't set to null even if string is blank. " " => ""
|
32
|
-
auto_strip_attributes :email, :
|
32
|
+
auto_strip_attributes :email, nullify: false
|
33
33
|
|
34
34
|
# Use with attributes that are not mapped to a column
|
35
35
|
auto_strip_attributes :password, virtual: true
|
@@ -41,12 +41,12 @@ end
|
|
41
41
|
|
42
42
|
By default the following options are defined (listed in the order of processing):
|
43
43
|
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
44
|
+
- `:strip` (enabled by default) - removes whitespaces from the beginning and the end of string. Works exactly same as `String#strip`, i.e., may not strip non-ASCII whitespaces.
|
45
|
+
- `:nullify` (enabled by default) - replaces empty strings with nil.
|
46
|
+
- `:squish` (disabled by default) - replaces all consecutive Unicode whitespace characters (including tabs and new lines) with single space (U+0020). Works exactly same as Rails `String#squish`
|
47
|
+
- `:delete_whitespaces` (disabled by default) - deletes all spaces (U+0020) and tabs (U+0009).
|
48
|
+
- `:convert_non_breaking_spaces` (disabled by default) - converts non-breaking spaces (U+00A0) to normal spaces (U+0020).
|
49
|
+
- `:virtual` (disabled by default) - By default `auto_strip_attributes` doesn't work with non-persistent attributes (e.g., attributes that are created with `attr_accessor`). This is to avoid calling their custom getter/setter methods. Use this option with non-persistent attributes.
|
50
50
|
|
51
51
|
### Custom Filters
|
52
52
|
|
@@ -67,7 +67,8 @@ class AutoStripAttributes::Config
|
|
67
67
|
(value.respond_to?(:'blank?') and value.respond_to?(:'empty?') and value.blank?) ? nil : value
|
68
68
|
end
|
69
69
|
set_filter :squish => false do |value|
|
70
|
-
value.respond_to?(:gsub) ? value.gsub(
|
70
|
+
value = value.respond_to?(:gsub) ? value.gsub(/[[:space:]]+/, ' ') : value
|
71
|
+
value.respond_to?(:strip) ? value.strip : value
|
71
72
|
end
|
72
73
|
set_filter :delete_whitespaces => false do |value|
|
73
74
|
value.respond_to?(:delete) ? value.delete(" \t") : value
|
@@ -154,12 +154,13 @@ describe AutoStripAttributes do
|
|
154
154
|
class MockRecordWithSqueeze < MockRecordParent #< ActiveRecord::Base
|
155
155
|
#column :foo, :st
|
156
156
|
attr_accessor :foo
|
157
|
-
|
157
|
+
# test that `:squish => true` implies `:strip => true`
|
158
|
+
auto_strip_attributes :foo, :squish => true, :strip => false
|
158
159
|
end
|
159
160
|
|
160
161
|
it "should squish string also form inside" do
|
161
162
|
@record = MockRecordWithSqueeze.new
|
162
|
-
@record.foo = " aaa\
|
163
|
+
@record.foo = " aaa \u0009 \u000A \u000B \u000C \u000D \u0020 \u0085 \u00A0 \u1680 \u2000 \u2001 \u2002 \u2003 \u2004 \u2005 \u2006 \u2007 \u2008 \u2009 \u200A \u2028 \u2029 \u202F \u205F \u3000 bbb \u00A0 "
|
163
164
|
@record.valid?
|
164
165
|
@record.foo.must_equal "aaa bbb"
|
165
166
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_strip_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olli Huotari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project: auto_strip_attributes
|
111
|
-
rubygems_version: 2.6.
|
111
|
+
rubygems_version: 2.6.14
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Removes unnecessary whitespaces in attributes. Extension to ActiveRecord
|